From 1d57c20dfd79c64837cf1ec357ab402f2158227e Mon Sep 17 00:00:00 2001 From: Cowtowncoder Date: Thu, 26 Mar 2015 12:49:58 -0700 Subject: [PATCH] Fix #735 --- release-notes/VERSION | 8 +++- .../databind/deser/std/MapDeserializer.java | 8 +++- .../deser/TestCustomDeserializers.java | 47 ++++++++++++++++++- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/release-notes/VERSION b/release-notes/VERSION index 18b83abed7..a854f644e3 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -4,11 +4,15 @@ Project: jackson-databind === Releases === ------------------------------------------------------------------------ -2.4.6 (not yet released) +2.4.5.1 (26-Mar-2015) -#706: Add support for @JsonUnwrapper via JSON Schema module +Special one-off "micro patch" for: + +#706: Add support for `@JsonUnwrapped` via JSON Schema module #707: Error in getting string representation of an ObjectNode with a float number value (reported by @navidqar) +#735: @JsonDeserialize on Map with contentUsing custom deserializer overwrites default behavior + (reported by blackfyre512@github) (regression due to #604) 2.4.5 (13-Jan-2015) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java index e6a9b1e67c..a01167fe78 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java @@ -297,7 +297,13 @@ public JsonDeserializer getContentDeserializer() { */ @Override public boolean isCachable() { - return (_valueTypeDeserializer == null) && (_ignorableProperties == null); + /* As per [databind#735], existence of value or key deserializer (only passed + * if annotated to use non-standard one) should also prevent caching. + */ + return (_valueDeserializer == null) + && (_keyDeserializer == null) + && (_valueTypeDeserializer == null) + && (_ignorableProperties == null); } @Override diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java b/src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java index c7dcc62958..1b7a1e4c5e 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -228,9 +229,36 @@ public JsonDeserializer createContextual(DeserializationContext ctxt, BeanPro } return this; } - + } + + // For [databind#735] + public static class TestMapBean735 { + + @JsonDeserialize(contentUsing = CustomDeserializer735.class) + public Map map1; + + public Map map2; + } + + public static class TestListBean735 { + + @JsonDeserialize(contentUsing = CustomDeserializer735.class) + public List list1; + + public List list2; } + public static class CustomDeserializer735 extends StdDeserializer { + public CustomDeserializer735() { + super(Integer.class); + } + + @Override + public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + return 100 * p.getValueAsInt(); + } + } + /* /********************************************************** /* Unit tests @@ -332,4 +360,21 @@ public void testContextReadValue() throws Exception assertNotNull(w.value.inner); assertEquals(-13, w.value.inner.x); } + + // [databind#735]: erroneous application of custom deserializer + public void testCustomMapValueDeser735() throws Exception { + String json = "{\"map1\":{\"a\":1},\"map2\":{\"a\":1}}"; + TestMapBean735 bean = MAPPER.readValue(json, TestMapBean735.class); + + assertEquals(100, bean.map1.get("a").intValue()); + assertEquals(1, bean.map2.get("a").intValue()); + } + + public void testCustomListValueDeser735() throws Exception { + String json = "{\"list1\":[1],\"list2\":[1]}"; + TestListBean735 bean = MAPPER.readValue(json, TestListBean735.class); + + assertEquals(100, bean.list1.get(0).intValue()); + assertEquals(1, bean.list2.get(0).intValue()); + } }