@@ -81,7 +81,6 @@ private LowerCaseEnum() { }
81
81
public String toString () { return name ().toLowerCase (); }
82
82
}
83
83
84
- // for [JACKSON-749]
85
84
protected enum EnumWithJsonValue {
86
85
A ("foo" ), B ("bar" );
87
86
private final String name ;
@@ -92,13 +91,11 @@ private EnumWithJsonValue(String n) {
92
91
@ Override
93
92
public String toString () { return name ; }
94
93
}
95
-
96
- // [JACKSON-810]
94
+
97
95
static class ClassWithEnumMapKey {
98
- @ JsonProperty Map <TestEnum , String > map ;
96
+ @ JsonProperty Map <TestEnum , String > map ;
99
97
}
100
98
101
- // [JACKSON-834]
102
99
protected enum TestEnumFor834
103
100
{
104
101
ENUM_A (1 ), ENUM_B (2 ), ENUM_C (3 );
@@ -127,7 +124,7 @@ protected enum TestEnum324
127
124
}
128
125
}
129
126
130
- // [Issue #745]
127
+ // [databind #745]
131
128
static class DelegatingDeserializers extends Deserializers .Base
132
129
{
133
130
@ Override
@@ -145,7 +142,7 @@ public JsonDeserializer<?> findEnumDeserializer(final Class<?> type, final Deser
145
142
}
146
143
}
147
144
148
- // [Issue #745]
145
+ // [databind #745]
149
146
static class DelegatingDeserializersModule extends SimpleModule
150
147
{
151
148
@ Override
@@ -154,14 +151,29 @@ public void setupModule(final SetupContext context) {
154
151
}
155
152
}
156
153
154
+ // [databind#677]
155
+ static enum EnumWithPropertyAnno {
156
+ @ JsonProperty ("a" )
157
+ A ,
158
+
159
+ // For this value, force use of anonymous sub-class, to ensure things still work
160
+ @ JsonProperty ("b" )
161
+ B {
162
+ @ Override
163
+ public String toString () {
164
+ return "bb" ;
165
+ }
166
+ }
167
+ ;
168
+ }
169
+
157
170
/*
158
171
/**********************************************************
159
172
/* Tests
160
173
/**********************************************************
161
174
*/
162
175
163
176
protected final ObjectMapper MAPPER = new ObjectMapper ();
164
-
165
177
166
178
public void testSimple () throws Exception
167
179
{
@@ -226,15 +238,13 @@ public void testEnumMaps() throws Exception
226
238
new TypeReference <EnumMap <TestEnum ,String >>() { });
227
239
assertEquals ("value" , value .get (TestEnum .OK ));
228
240
}
229
-
230
- // Test [JACKSON-214]
241
+
231
242
public void testSubclassedEnums () throws Exception
232
243
{
233
244
EnumWithSubClass value = MAPPER .readValue ("\" A\" " , EnumWithSubClass .class );
234
245
assertEquals (EnumWithSubClass .A , value );
235
246
}
236
247
237
- // [JACKSON-193]
238
248
public void testCreatorEnums () throws Exception {
239
249
EnumWithCreator value = MAPPER .readValue ("\" enumA\" " , EnumWithCreator .class );
240
250
assertEquals (EnumWithCreator .A , value );
@@ -244,8 +254,7 @@ public void testCreatorEnumsFromBigDecimal() throws Exception {
244
254
EnumWithBDCreator value = MAPPER .readValue ("\" 8.0\" " , EnumWithBDCreator .class );
245
255
assertEquals (EnumWithBDCreator .E8 , value );
246
256
}
247
-
248
- // [JACKSON-212]
257
+
249
258
public void testToStringEnums () throws Exception
250
259
{
251
260
// can't reuse global one due to reconfig
@@ -255,7 +264,6 @@ public void testToStringEnums() throws Exception
255
264
assertEquals (LowerCaseEnum .C , value );
256
265
}
257
266
258
- // [JACKSON-212]
259
267
public void testToStringEnumMaps () throws Exception
260
268
{
261
269
// can't reuse global one due to reconfig
@@ -266,7 +274,6 @@ public void testToStringEnumMaps() throws Exception
266
274
assertEquals ("value" , value .get (LowerCaseEnum .A ));
267
275
}
268
276
269
- // [JACKSON-412], disallow use of numbers
270
277
public void testNumbersToEnums () throws Exception
271
278
{
272
279
// by default numbers are fine:
@@ -293,7 +300,6 @@ public void testNumbersToEnums() throws Exception
293
300
}
294
301
}
295
302
296
- // [JACKSON-684], enums using index
297
303
public void testEnumsWithIndex () throws Exception
298
304
{
299
305
ObjectMapper m = new ObjectMapper ();
@@ -303,8 +309,7 @@ public void testEnumsWithIndex() throws Exception
303
309
TestEnum result = m .readValue (json , TestEnum .class );
304
310
assertSame (TestEnum .RULES , result );
305
311
}
306
-
307
- // [JACKSON-749]: @JsonValue should be considered as well
312
+
308
313
public void testEnumsWithJsonValue () throws Exception
309
314
{
310
315
// first, enum as is
@@ -329,8 +334,6 @@ public void testEnumsWithJsonValue() throws Exception
329
334
assertEquals (Integer .valueOf (13 ), map .get (EnumWithJsonValue .A ));
330
335
}
331
336
332
- // [JACKSON-756], next three tests
333
-
334
337
public void testEnumWithCreatorEnumMaps () throws Exception {
335
338
EnumMap <EnumWithCreator ,String > value = MAPPER .readValue ("{\" enumA\" :\" value\" }" ,
336
339
new TypeReference <EnumMap <EnumWithCreator ,String >>() {});
@@ -386,15 +389,14 @@ public void testDoNotAllowUnknownEnumValuesAsMapKeysWhenReadAsNullDisabled() thr
386
389
}
387
390
}
388
391
389
- // [JACKSON-834]
390
392
public void testEnumsFromInts () throws Exception
391
393
{
392
394
Object ob = MAPPER .readValue ("1 " , TestEnumFor834 .class );
393
395
assertEquals (TestEnumFor834 .class , ob .getClass ());
394
396
assertSame (TestEnumFor834 .ENUM_A , ob );
395
397
}
396
398
397
- // [Issue #141]: allow mapping of empty String into null
399
+ // [databind #141]: allow mapping of empty String into null
398
400
public void testEnumsWithEmpty () throws Exception
399
401
{
400
402
final ObjectMapper mapper = new ObjectMapper ();
@@ -413,7 +415,7 @@ public void testGenericEnumDeserialization() throws Exception
413
415
assertEquals (TestEnum .JACKSON , mapper .readValue (quote ("jackson" ), TestEnum .class ));
414
416
}
415
417
416
- // [Issue #324]
418
+ // [databind #324]
417
419
public void testExceptionFromCreator () throws Exception
418
420
{
419
421
try {
@@ -424,7 +426,7 @@ public void testExceptionFromCreator() throws Exception
424
426
}
425
427
}
426
428
427
- // [Issue #381]
429
+ // [databind #381]
428
430
public void testUnwrappedEnum () throws Exception {
429
431
final ObjectMapper mapper = new ObjectMapper ();
430
432
mapper .enable (DeserializationFeature .UNWRAP_SINGLE_VALUE_ARRAYS );
@@ -443,7 +445,7 @@ public void testUnwrappedEnumException() throws Exception {
443
445
}
444
446
}
445
447
446
- // [Issue #149]: 'stringified' indexes for enums
448
+ // [databind #149]: 'stringified' indexes for enums
447
449
public void testIndexAsString () throws Exception
448
450
{
449
451
// first, regular index ought to work fine
@@ -455,7 +457,7 @@ public void testIndexAsString() throws Exception
455
457
assertSame (TestEnum .values ()[1 ], en );
456
458
}
457
459
458
- // [Issue #745]
460
+ // [databind #745]
459
461
public void testDeserializerForCreatorWithEnumMaps () throws Exception
460
462
{
461
463
final ObjectMapper mapper = new ObjectMapper ();
@@ -464,4 +466,19 @@ public void testDeserializerForCreatorWithEnumMaps() throws Exception
464
466
new TypeReference <EnumMap <EnumWithCreator ,String >>() {});
465
467
assertEquals ("value" , value .get (EnumWithCreator .A ));
466
468
}
469
+
470
+ public void testEnumWithJsonPropertyRename () throws Exception
471
+ {
472
+ String json = MAPPER .writeValueAsString (new EnumWithPropertyAnno [] {
473
+ EnumWithPropertyAnno .B , EnumWithPropertyAnno .A
474
+ });
475
+ assertEquals ("[\" b\" ,\" a\" ]" , json );
476
+
477
+ // and while not really proper place, let's also verify deser while we're at it
478
+ EnumWithPropertyAnno [] result = MAPPER .readValue (json , EnumWithPropertyAnno [].class );
479
+ assertNotNull (result );
480
+ assertEquals (2 , result .length );
481
+ assertSame (EnumWithPropertyAnno .B , result [0 ]);
482
+ assertSame (EnumWithPropertyAnno .A , result [1 ]);
483
+ }
467
484
}
0 commit comments