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")); }
public void testSimpleIgnoreAndRename() { POJOPropertiesCollector coll = collector(mapper, IgnoredRenamedSetter.class, true); Map<String, POJOPropertyBuilder> props = coll.getPropertyMap(); assertEquals(1, props.size()); POJOPropertyBuilder prop = props.get("y"); assertNotNull(prop); assertTrue(prop.hasSetter()); assertFalse(prop.hasGetter()); assertFalse(prop.hasField()); }
public void testMergeWithRename() { POJOPropertiesCollector coll = collector(mapper, MergedProperties.class, true); Map<String, POJOPropertyBuilder> props = coll.getPropertyMap(); assertEquals(1, props.size()); POJOPropertyBuilder prop = props.get("x"); assertNotNull(prop); assertTrue(prop.hasSetter()); assertFalse(prop.hasGetter()); assertTrue(prop.hasField()); }
public void testSimpleGetterVisibility() { POJOPropertiesCollector coll = collector(mapper, SimpleGetterVisibility.class, true); Map<String, POJOPropertyBuilder> props = coll.getPropertyMap(); assertEquals(1, props.size()); POJOPropertyBuilder prop = props.get("a"); assertNotNull(prop); assertFalse(prop.hasSetter()); assertTrue(prop.hasGetter()); assertFalse(prop.hasField()); }
public void testSimpleFieldVisibility() { // false -> deserialization POJOPropertiesCollector coll = collector(mapper, SimpleFieldDeser.class, false); Map<String, POJOPropertyBuilder> props = coll.getPropertyMap(); assertEquals(1, props.size()); POJOPropertyBuilder prop = props.get("values"); assertNotNull(prop); assertFalse(prop.hasSetter()); assertFalse(prop.hasGetter()); assertTrue(prop.hasField()); }
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")); }
@JsonIgnore public String getName() { return (String) additionalProperties.get("name"); }
public void testStaticMethods() throws Exception { ObjectMapper m = new ObjectMapper(); Map<String, Object> result = writeAndMap(m, new GetterBean()); assertEquals(1, result.size()); assertEquals(Integer.valueOf(3), result.get("x")); }