|
10 | 10 | import com.fasterxml.jackson.annotation.JsonCreator;
|
11 | 11 | import com.fasterxml.jackson.annotation.JsonProperty;
|
12 | 12 | import com.fasterxml.jackson.core.*;
|
| 13 | +import com.fasterxml.jackson.core.type.TypeReference; |
13 | 14 | import com.fasterxml.jackson.databind.*;
|
14 | 15 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
15 | 16 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
@@ -228,9 +229,36 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanPro
|
228 | 229 | }
|
229 | 230 | return this;
|
230 | 231 | }
|
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; |
232 | 249 | }
|
233 | 250 |
|
| 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 | + |
234 | 262 | /*
|
235 | 263 | /**********************************************************
|
236 | 264 | /* Unit tests
|
@@ -332,4 +360,21 @@ public void testContextReadValue() throws Exception
|
332 | 360 | assertNotNull(w.value.inner);
|
333 | 361 | assertEquals(-13, w.value.inner.x);
|
334 | 362 | }
|
| 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 | + } |
335 | 380 | }
|
0 commit comments