File tree 1 file changed +56
-0
lines changed
src/test/java/com/fasterxml/jackson/failing 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .failing ;
2
+
3
+ import java .util .HashMap ;
4
+ import java .util .Map ;
5
+
6
+ import com .fasterxml .jackson .annotation .JsonCreator ;
7
+ import com .fasterxml .jackson .annotation .JsonValue ;
8
+ import com .fasterxml .jackson .core .type .TypeReference ;
9
+ import com .fasterxml .jackson .databind .BaseMapTest ;
10
+ import com .fasterxml .jackson .databind .ObjectMapper ;
11
+
12
+ public class EnumAsMapKey2725Test extends BaseMapTest
13
+ {
14
+ // [databind#2725]
15
+ enum TestEnum2725 {
16
+ FOO (1 );
17
+
18
+ private final int i ;
19
+
20
+ TestEnum2725 (final int i ) {
21
+ this .i = i ;
22
+ }
23
+
24
+ @ JsonValue
25
+ public int getI () {
26
+ return i ;
27
+ }
28
+
29
+ @ JsonCreator
30
+ public static TestEnum2725 getByIntegerId (final Integer id ) {
31
+ return id == FOO .i ? FOO : null ;
32
+ }
33
+
34
+ @ JsonCreator
35
+ public static TestEnum2725 getByStringId (final String id ) {
36
+ return Integer .parseInt (id ) == FOO .i ? FOO : null ;
37
+ }
38
+ }
39
+
40
+ private final ObjectMapper MAPPER = newJsonMapper ();
41
+
42
+ // [databind#2725]
43
+ public void testEnumAsMapKey2725 () throws Exception
44
+ {
45
+ final Map <TestEnum2725 , String > input = new HashMap <>();
46
+ input .put (TestEnum2725 .FOO , "Hello" );
47
+
48
+ final String json = MAPPER .writeValueAsString (input );
49
+
50
+ final Map <TestEnum2725 , String > output = MAPPER .readValue (json ,
51
+ new TypeReference <Map <TestEnum2725 , String >>() { });
52
+
53
+ assertNotNull (output );
54
+ assertEquals (1 , output .size ());
55
+ }
56
+ }
You can’t perform that action at this time.
0 commit comments