@@ -46,59 +46,82 @@ public void setValue(Object o) {
46
46
value = o ;
47
47
}
48
48
}
49
-
49
+
50
+ // for [databind#2605]
51
+ static class EnumContaintingClass <ENUM_TYPE extends Enum <ENUM_TYPE >> {
52
+ @ JsonTypeInfo (
53
+ use = JsonTypeInfo .Id .CLASS ,
54
+ include = JsonTypeInfo .As .PROPERTY ,
55
+ property = "@class"
56
+ )
57
+ public ENUM_TYPE selected ;
58
+
59
+ protected EnumContaintingClass () { }
60
+
61
+ public EnumContaintingClass (ENUM_TYPE selected ) {
62
+ this .selected = selected ;
63
+ }
64
+ }
65
+
50
66
/*
51
67
/**********************************************************
52
68
/* Unit tests
53
69
/**********************************************************
54
70
*/
55
71
72
+ private final ObjectMapper MAPPER = newJsonMapper ();
73
+
56
74
public void testTagList () throws Exception
57
75
{
58
- ObjectMapper m = new ObjectMapper ();
59
76
TagList list = new TagList ();
60
77
list .add (Tag .A );
61
78
list .add (Tag .B );
62
- String json = m .writeValueAsString (list );
79
+ String json = MAPPER .writeValueAsString (list );
63
80
64
- TagList result = m .readValue (json , TagList .class );
81
+ TagList result = MAPPER .readValue (json , TagList .class );
65
82
assertEquals (2 , result .size ());
66
83
assertSame (Tag .A , result .get (0 ));
67
84
assertSame (Tag .B , result .get (1 ));
68
85
}
69
86
70
87
public void testEnumInterface () throws Exception
71
88
{
72
- ObjectMapper m = new ObjectMapper ();
73
- String json = m .writeValueAsString (Tag .B );
74
- EnumInterface result = m .readValue (json , EnumInterface .class );
89
+ String json = MAPPER .writeValueAsString (Tag .B );
90
+ EnumInterface result = MAPPER .readValue (json , EnumInterface .class );
75
91
assertSame (Tag .B , result );
76
92
}
77
93
78
94
public void testEnumInterfaceList () throws Exception
79
95
{
80
- ObjectMapper m = new ObjectMapper ();
81
96
EnumInterfaceList list = new EnumInterfaceList ();
82
97
list .add (Tag .A );
83
98
list .add (Tag .B );
84
- String json = m .writeValueAsString (list );
99
+ String json = MAPPER .writeValueAsString (list );
85
100
86
- EnumInterfaceList result = m .readValue (json , EnumInterfaceList .class );
101
+ EnumInterfaceList result = MAPPER .readValue (json , EnumInterfaceList .class );
87
102
assertEquals (2 , result .size ());
88
103
assertSame (Tag .A , result .get (0 ));
89
104
assertSame (Tag .B , result .get (1 ));
90
105
}
91
106
92
107
public void testUntypedEnum () throws Exception
93
108
{
94
- ObjectMapper mapper = new ObjectMapper ();
95
- String str = mapper .writeValueAsString (new UntypedEnumBean (TestEnum .B ));
96
- UntypedEnumBean result = mapper .readValue (str , UntypedEnumBean .class );
109
+ String str = MAPPER .writeValueAsString (new UntypedEnumBean (TestEnum .B ));
110
+ UntypedEnumBean result = MAPPER .readValue (str , UntypedEnumBean .class );
97
111
assertNotNull (result );
98
112
assertNotNull (result .value );
99
113
Object ob = result .value ;
100
114
assertSame (TestEnum .class , ob .getClass ());
101
115
assertEquals (TestEnum .B , result .value );
102
116
}
103
-
117
+
118
+ // for [databind#2605]
119
+ public void testRoundtrip () throws Exception
120
+ {
121
+ EnumContaintingClass <TestEnum > input = new EnumContaintingClass <TestEnum >(TestEnum .B );
122
+ String json = MAPPER .writeValueAsString (input );
123
+ // Object o = MAPPER.readerFor(EnumContaintingClass.class).readValue(json);
124
+ Object o = MAPPER .readValue (json , EnumContaintingClass .class );
125
+ assertNotNull (o );
126
+ }
104
127
}
0 commit comments