|
5 | 5 |
|
6 | 6 | import com.fasterxml.jackson.annotation.JsonCreator;
|
7 | 7 | import com.fasterxml.jackson.annotation.JsonValue;
|
8 |
| -import com.fasterxml.jackson.core.type.TypeReference; |
| 8 | +import com.fasterxml.jackson.databind.BaseMapTest; |
9 | 9 | import com.fasterxml.jackson.databind.ObjectMapper;
|
10 |
| -import com.fasterxml.jackson.test.BaseTest; |
11 | 10 |
|
12 |
| -public class TestMapJsonValueKey extends BaseTest |
| 11 | +// [Issue#47] |
| 12 | +public class TestMapJsonValueKey extends BaseMapTest |
13 | 13 | {
|
14 | 14 | public static class Wat
|
15 | 15 | {
|
16 | 16 | private final String wat;
|
17 | 17 |
|
18 | 18 | @JsonCreator
|
19 |
| - Wat(String wat) |
20 |
| - { |
| 19 | + Wat(String wat) { |
21 | 20 | this.wat = wat;
|
22 | 21 | }
|
23 | 22 |
|
24 | 23 | @JsonValue
|
25 |
| - public String getWat() |
26 |
| - { |
| 24 | + public String getWat() { |
27 | 25 | return wat;
|
28 | 26 | }
|
29 | 27 |
|
30 | 28 | @Override
|
31 |
| - public String toString() |
32 |
| - { |
33 |
| - return "[Wat: " + wat + "]"; |
| 29 | + public String toString() { |
| 30 | + return "(String)[Wat: " + wat + "]"; |
34 | 31 | }
|
35 | 32 | }
|
36 | 33 |
|
37 | 34 | public void testMapJsonValueKey()
|
38 | 35 | throws Exception
|
39 | 36 | {
|
40 |
| - Map<Wat, Boolean> map = new HashMap<Wat, Boolean>(); |
41 |
| - map.put(new Wat("3"), true); |
42 |
| - map.put(new Wat("x"), false); |
43 |
| - |
44 |
| - TypeReference<Map<Wat, Boolean>> type = new TypeReference<Map<Wat, Boolean>>(){}; |
| 37 | + Map<Wat, Boolean> input = new HashMap<Wat, Boolean>(); |
| 38 | + input.put(new Wat("3"), true); |
45 | 39 |
|
46 | 40 | ObjectMapper mapper = new ObjectMapper();
|
47 |
| - assertEquals(map, mapper.readValue(mapper.writeValueAsBytes(map), type)); |
| 41 | + String json = mapper.writeValueAsString(input); |
| 42 | + assertEquals(aposToQuotes("{'3':'true'}"), json); |
48 | 43 | }
|
49 | 44 | }
|
0 commit comments