public void testExplicitIgnoralWithBean() throws Exception {
   IgnoreSome value = new IgnoreSome();
   Map<String, Object> result = writeAndMap(MAPPER, value);
   assertEquals(2, result.size());
   // verify that specified fields are ignored
   assertFalse(result.containsKey("b"));
   assertFalse(result.containsKey("c"));
   // and that others are not
   assertEquals(Integer.valueOf(value.a), result.get("a"));
   assertEquals(value.getD(), result.get("d"));
 }
Exemplo n.º 2
0
 // Check if a value exists before getting it
 // AG
 static Object getFromMap(Object map, String key) {
   if (map instanceof Map<?, ?>) {
     Map<?, ?> castMap = (Map<?, ?>) map;
     if (castMap.containsKey(key)) {
       return castMap.get(key);
     } else {
       return null;
     }
   } else {
     return null;
   }
 }
 public void testExplicitIgnoralWithMap() throws Exception {
   // test simulating need to filter out metadata like class name
   MyMap value = new MyMap();
   value.put("a", "b");
   value.put("@class", MyMap.class.getName());
   Map<String, Object> result = writeAndMap(MAPPER, value);
   assertEquals(1, result.size());
   // verify that specified field is ignored
   assertFalse(result.containsKey("@class"));
   // and that others are not
   assertEquals(value.get("a"), result.get("a"));
 }
Exemplo n.º 4
0
 protected Map<?, ?> _orderEntries(Map<?, ?> input, JsonGenerator gen, SerializerProvider provider)
     throws IOException {
   // minor optimization: may already be sorted?
   if (input instanceof SortedMap<?, ?>) {
     return input;
   }
   // [databind#1411]: TreeMap does not like null key...
   if (input.containsKey(null)) {
     TreeMap<Object, Object> result = new TreeMap<Object, Object>();
     for (Map.Entry<?, ?> entry : input.entrySet()) {
       Object key = entry.getKey();
       if (key == null) {
         _writeNullKeyedEntry(gen, provider, entry.getValue());
         continue;
       }
       result.put(key, entry.getValue());
     }
     return result;
   }
   return new TreeMap<Object, Object>(input);
 }