Skip to content

Commit 1d57c20

Browse files
committed
Fix #735
1 parent 36d9b59 commit 1d57c20

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

release-notes/VERSION

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7-
2.4.6 (not yet released)
7+
2.4.5.1 (26-Mar-2015)
88

9-
#706: Add support for @JsonUnwrapper via JSON Schema module
9+
Special one-off "micro patch" for:
10+
11+
#706: Add support for `@JsonUnwrapped` via JSON Schema module
1012
#707: Error in getting string representation of an ObjectNode with a float number value
1113
(reported by @navidqar)
14+
#735: @JsonDeserialize on Map with contentUsing custom deserializer overwrites default behavior
15+
(reported by blackfyre512@github) (regression due to #604)
1216

1317
2.4.5 (13-Jan-2015)
1418

src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,13 @@ public JsonDeserializer<Object> getContentDeserializer() {
297297
*/
298298
@Override
299299
public boolean isCachable() {
300-
return (_valueTypeDeserializer == null) && (_ignorableProperties == null);
300+
/* As per [databind#735], existence of value or key deserializer (only passed
301+
* if annotated to use non-standard one) should also prevent caching.
302+
*/
303+
return (_valueDeserializer == null)
304+
&& (_keyDeserializer == null)
305+
&& (_valueTypeDeserializer == null)
306+
&& (_ignorableProperties == null);
301307
}
302308

303309
@Override

src/test/java/com/fasterxml/jackson/databind/deser/TestCustomDeserializers.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.fasterxml.jackson.annotation.JsonCreator;
1111
import com.fasterxml.jackson.annotation.JsonProperty;
1212
import com.fasterxml.jackson.core.*;
13+
import com.fasterxml.jackson.core.type.TypeReference;
1314
import com.fasterxml.jackson.databind.*;
1415
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
1516
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@@ -228,9 +229,36 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanPro
228229
}
229230
return this;
230231
}
231-
232+
}
233+
234+
// For [databind#735]
235+
public static class TestMapBean735 {
236+
237+
@JsonDeserialize(contentUsing = CustomDeserializer735.class)
238+
public Map<String, Integer> map1;
239+
240+
public Map<String, Integer> map2;
241+
}
242+
243+
public static class TestListBean735 {
244+
245+
@JsonDeserialize(contentUsing = CustomDeserializer735.class)
246+
public List<Integer> list1;
247+
248+
public List<Integer> list2;
232249
}
233250

251+
public static class CustomDeserializer735 extends StdDeserializer<Integer> {
252+
public CustomDeserializer735() {
253+
super(Integer.class);
254+
}
255+
256+
@Override
257+
public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
258+
return 100 * p.getValueAsInt();
259+
}
260+
}
261+
234262
/*
235263
/**********************************************************
236264
/* Unit tests
@@ -332,4 +360,21 @@ public void testContextReadValue() throws Exception
332360
assertNotNull(w.value.inner);
333361
assertEquals(-13, w.value.inner.x);
334362
}
363+
364+
// [databind#735]: erroneous application of custom deserializer
365+
public void testCustomMapValueDeser735() throws Exception {
366+
String json = "{\"map1\":{\"a\":1},\"map2\":{\"a\":1}}";
367+
TestMapBean735 bean = MAPPER.readValue(json, TestMapBean735.class);
368+
369+
assertEquals(100, bean.map1.get("a").intValue());
370+
assertEquals(1, bean.map2.get("a").intValue());
371+
}
372+
373+
public void testCustomListValueDeser735() throws Exception {
374+
String json = "{\"list1\":[1],\"list2\":[1]}";
375+
TestListBean735 bean = MAPPER.readValue(json, TestListBean735.class);
376+
377+
assertEquals(100, bean.list1.get(0).intValue());
378+
assertEquals(1, bean.list2.get(0).intValue());
379+
}
335380
}

0 commit comments

Comments
 (0)