|
1 | 1 | package com.fasterxml.jackson.databind.filter;
|
2 | 2 |
|
3 | 3 | import java.io.IOException;
|
| 4 | +import java.util.Map; |
4 | 5 |
|
5 | 6 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
6 | 7 | import com.fasterxml.jackson.databind.*;
|
7 | 8 | import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
|
8 | 9 |
|
9 | 10 | public class ProblemHandlerTest extends BaseMapTest
|
10 | 11 | {
|
| 12 | + static class WeirdKeyHandler |
| 13 | + extends DeserializationProblemHandler |
| 14 | + { |
| 15 | + protected final Object key; |
| 16 | + |
| 17 | + public WeirdKeyHandler(Object key0) { |
| 18 | + key = key0; |
| 19 | + } |
| 20 | + |
| 21 | + @Override |
| 22 | + public Object handleWeirdKey(DeserializationContext ctxt, |
| 23 | + Class<?> rawKeyType, String keyValue, |
| 24 | + String failureMsg) |
| 25 | + throws IOException |
| 26 | + { |
| 27 | + return key; |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + static class IntKeyMapWrapper { |
| 32 | + public Map<Integer,String> stuff; |
| 33 | + } |
| 34 | + |
11 | 35 | static class TypeIdHandler
|
12 | 36 | extends DeserializationProblemHandler
|
13 | 37 | {
|
@@ -37,6 +61,18 @@ static class BaseWrapper {
|
37 | 61 | /**********************************************************
|
38 | 62 | */
|
39 | 63 |
|
| 64 | + public void testWeirdKeyHandling() throws Exception |
| 65 | + { |
| 66 | + ObjectMapper mapper = new ObjectMapper() |
| 67 | + .addHandler(new WeirdKeyHandler(7)); |
| 68 | + IntKeyMapWrapper w = mapper.readValue("{\"stuff\":{\"foo\":\"abc\"}}", |
| 69 | + IntKeyMapWrapper.class); |
| 70 | + Map<Integer,String> map = w.stuff; |
| 71 | + assertEquals(1, map.size()); |
| 72 | + assertEquals("abc", map.values().iterator().next()); |
| 73 | + assertEquals(Integer.valueOf(7), map.keySet().iterator().next()); |
| 74 | + } |
| 75 | + |
40 | 76 | public void testInvalidTypeId() throws Exception
|
41 | 77 | {
|
42 | 78 | ObjectMapper mapper = new ObjectMapper()
|
|
0 commit comments