Skip to content

Commit

Permalink
Fix #735
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 26, 2015
1 parent 36d9b59 commit 1d57c20
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
8 changes: 6 additions & 2 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,13 @@ public JsonDeserializer<Object> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Integer> map1;

public Map<String, Integer> map2;
}

public static class TestListBean735 {

@JsonDeserialize(contentUsing = CustomDeserializer735.class)
public List<Integer> list1;

public List<Integer> list2;
}

public static class CustomDeserializer735 extends StdDeserializer<Integer> {
public CustomDeserializer735() {
super(Integer.class);
}

@Override
public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return 100 * p.getValueAsInt();
}
}

/*
/**********************************************************
/* Unit tests
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 1d57c20

Please sign in to comment.