Fixed [JACKSON-313], ignored properties should not be passed to @JsonAnySetter
diff --git a/release-notes/VERSION b/release-notes/VERSION index 74b2c96..0d5a445 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION
@@ -16,6 +16,7 @@ * [JACKSON-303] JAXB annotation @XmlAccessorType(XmlAccessType.NONE) seems to not work correctly during deserialisation process (reported by David M) + * [JACKSON-313] Ignorable properties should not be passed to any-setter. * [JACKSON-336] Generics handling: Map type not handled if intermediate types with just one generic parameter
diff --git a/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializer.java b/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializer.java index fee6fe8..84ea22e 100644 --- a/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializer.java +++ b/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializer.java
@@ -389,10 +389,17 @@ prop.deserializeAndSet(jp, ctxt, bean); continue; } + /* As per [JACKSON-313], things marked as ignorable should not be + * passed to any setter + */ + if (_ignorableProps != null && _ignorableProps.contains(propName)) { + jp.skipChildren(); + continue; + } if (_anySetter != null) { _anySetter.deserializeAndSet(jp, ctxt, bean, propName); continue; - } + } // Unknown: let's call handler method handleUnknownProperty(jp, ctxt, bean, propName); } @@ -479,9 +486,13 @@ prop.deserializeAndSet(jp, ctxt, bean); continue; } - /* 08-Nov-2009, tatus: Should we first check ignorable properties, - * and skip? For now, we'll just call any setter. + /* As per [JACKSON-313], things marked as ignorable should not be + * passed to any setter */ + if (_ignorableProps != null && _ignorableProps.contains(propName)) { + jp.skipChildren(); + continue; + } if (_anySetter != null) { _anySetter.deserializeAndSet(jp, ctxt, bean, propName); continue; @@ -579,6 +590,13 @@ buffer.bufferProperty(prop, prop.deserialize(jp, ctxt)); continue; } + /* As per [JACKSON-313], things marked as ignorable should not be + * passed to any setter + */ + if (_ignorableProps != null && _ignorableProps.contains(propName)) { + jp.skipChildren(); + continue; + } // "any property"? if (_anySetter != null) { buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(jp, ctxt)); @@ -619,6 +637,10 @@ protected void handleUnknownProperty(JsonParser jp, DeserializationContext ctxt, Object beanOrClass, String propName) throws IOException, JsonProcessingException { + /* 22-Aug-2010, tatu: Caller now mostly checks for ignorable properties, so + * following should not be necessary. However, "handleUnknownProperties()" seems + * to still possibly need it so it is left for now. + */ // If registered as ignorable, skip if (_ignoreAllUnknown || (_ignorableProps != null && _ignorableProps.contains(propName))) {
diff --git a/src/test/org/codehaus/jackson/map/deser/TestAnyProperties.java b/src/test/org/codehaus/jackson/map/deser/TestAnyProperties.java index 0fe81f1..f41df2c 100644 --- a/src/test/org/codehaus/jackson/map/deser/TestAnyProperties.java +++ b/src/test/org/codehaus/jackson/map/deser/TestAnyProperties.java
@@ -119,10 +119,11 @@ // [JACKSON-313] public void testIgnored() throws Exception { - Ignored bean = new ObjectMapper().readValue("{\"name\":\"bob\", \"bogus\":\"abc\", \"dummy\" : 13 }", + Ignored bean = new ObjectMapper().readValue("{\"name\":\"Bob\", \"bogus\": [ 1, 2, 3], \"dummy\" : 13 }", Ignored.class); assertNull(bean.map.get("dummy")); assertNull(bean.map.get("bogus")); assertEquals("Bob", bean.map.get("name")); + assertEquals(1, bean.map.size()); } }