Example #1
0
 public void testMapSelection() throws Exception {
   // Drop
   removeAll(MapHolder.class);
   // Create
   MapHolder mapHolder = new MapHolder();
   Book book = new Book("Book of Bokonon", "9");
   HashMap meta = new HashMap();
   meta.put("meta1", new Author("Geordi", "LaForge"));
   meta.put("meta2", new Author("Data", ""));
   meta.put("meta3", new Author("Scott", "Montgomery"));
   meta.put("book", book);
   mapHolder.setMeta(meta);
   // Save
   getStore().save(mapHolder);
   // Select
   List result =
       getStore()
           .find(
               "find mapholder where mapholder.meta['book'](book)=book and book.title like 'Book%'");
   Assert.assertEquals(result.size(), 1);
   result =
       getStore()
           .find("find mapholder where mapholder.meta['book'](book)=book and book.title like '9'");
   Assert.assertEquals(result.size(), 0);
 }
Example #2
0
 public void testStringCaseSensitivenessInMaps() throws Exception {
   // Drop
   removeAll(MapHolder.class);
   // Create
   MapHolder mapHolder = new MapHolder();
   Book book = new Book("Book of Bokonon", "9");
   HashMap meta = new HashMap();
   meta.put("book", book);
   mapHolder.setMeta(meta);
   getStore().save(mapHolder);
   // Select
   List result =
       getStore().find("find mapholder where mapholder.meta['book']=book and book.isbn='9'");
   Assert.assertEquals(result.size(), 1);
   result = getStore().find("find mapholder where mapholder.meta['bOoK']=book and book.isbn='9'");
   Assert.assertEquals(result.size(), 0);
 }
Example #3
0
  public void testJackson428() throws Exception {
    ObjectMapper serMapper = new ObjectMapper();

    TypeResolverBuilder<?> serializerTyper =
        new ObjectMapper.DefaultTypeResolverBuilder(ObjectMapper.DefaultTyping.NON_FINAL);
    serializerTyper = serializerTyper.init(JsonTypeInfo.Id.NAME, createTypeNameIdResolver(true));
    serializerTyper = serializerTyper.inclusion(JsonTypeInfo.As.PROPERTY);
    serMapper.setDefaultTyping(serializerTyper);

    // Let's start by constructing something to serialize first
    MapHolder holder = new MapHolder();
    holder.map = new HashMap<MapKey, List<Object>>();
    List<Object> ints = new ArrayList<Object>();
    ints.add(Integer.valueOf(3));
    holder.map.put(new MapKey("key"), ints);
    String json = serMapper.writeValueAsString(holder);

    // Then deserialize: need separate mapper to initialize type id resolver appropriately
    ObjectMapper deserMapper = new ObjectMapper();
    TypeResolverBuilder<?> deserializerTyper =
        new ObjectMapper.DefaultTypeResolverBuilder(ObjectMapper.DefaultTyping.NON_FINAL);
    deserializerTyper =
        deserializerTyper.init(JsonTypeInfo.Id.NAME, createTypeNameIdResolver(false));
    deserializerTyper = deserializerTyper.inclusion(JsonTypeInfo.As.PROPERTY);
    deserMapper.setDefaultTyping(deserializerTyper);

    MapHolder result = deserMapper.readValue(json, MapHolder.class);
    assertNotNull(result);
    Map<?, ?> map = result.map;
    assertEquals(1, map.size());
    Map.Entry<?, ?> entry = map.entrySet().iterator().next();
    Object key = entry.getKey();
    assertEquals(MapKey.class, key.getClass());
    Object value = entry.getValue();
    assertTrue(value instanceof List<?>);
    List<?> list = (List<?>) value;
    assertEquals(1, list.size());
    assertEquals(Integer.class, list.get(0).getClass());
    assertEquals(Integer.valueOf(3), list.get(0));
  }