File tree 3 files changed +38
-2
lines changed
main/java/com/fasterxml/jackson/databind/deser/std
test/java/com/fasterxml/jackson/databind/deser/enums
3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ Project: jackson-databind
25
25
(fix by Joo-Hyuk K)
26
26
#4450: Empty QName deserialized as `null`
27
27
(reported by @winfriedgerlach)
28
+ #4481: Unable to override `DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL`
29
+ with `JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_AS_NULL`
30
+ (reported by @luozhenyu)
28
31
29
32
2.17.0 (12-Mar-2024)
30
33
Original file line number Diff line number Diff line change @@ -486,8 +486,10 @@ protected CompactStringObjectMap _getToStringLookup(DeserializationContext ctxt)
486
486
487
487
// @since 2.15
488
488
protected boolean useNullForUnknownEnum (DeserializationContext ctxt ) {
489
- return Boolean .TRUE .equals (_useNullForUnknownEnum )
490
- || ctxt .isEnabled (DeserializationFeature .READ_UNKNOWN_ENUM_VALUES_AS_NULL );
489
+ if (_useNullForUnknownEnum != null ) {
490
+ return _useNullForUnknownEnum ;
491
+ }
492
+ return ctxt .isEnabled (DeserializationFeature .READ_UNKNOWN_ENUM_VALUES_AS_NULL );
491
493
}
492
494
493
495
// @since 2.15
Original file line number Diff line number Diff line change @@ -93,6 +93,16 @@ enum MyEnum2352_3 {
93
93
C ;
94
94
}
95
95
96
+ // [databind#4481]: override for "unknown as null"
97
+ enum Color {
98
+ RED , BLUE
99
+ }
100
+
101
+ static class Book4481 {
102
+ @ JsonFormat (without = JsonFormat .Feature .READ_UNKNOWN_ENUM_VALUES_AS_NULL )
103
+ public Color color ;
104
+ }
105
+
96
106
/*
97
107
/**********************************************************
98
108
/* Test methods, basic
@@ -304,4 +314,25 @@ public void testEnumWithNullForUnknownValueEnumSet() throws Exception {
304
314
assertEquals (1 , pojo .value .size ());
305
315
assertTrue (pojo .value .contains (MyEnum2352_3 .B ));
306
316
}
317
+
318
+ /*
319
+ /**********************************************************
320
+ /* Test methods, other
321
+ /**********************************************************
322
+ */
323
+
324
+ // [databind#4481]
325
+ @ Test
326
+ public void testDefaultFromNullOverride4481 () throws Exception
327
+ {
328
+ try {
329
+ Book4481 book = MAPPER .readerFor (Book4481 .class )
330
+ .with (DeserializationFeature .READ_UNKNOWN_ENUM_VALUES_AS_NULL )
331
+ .readValue ("{\" color\" :\" WHITE\" }" );
332
+ fail ("Should have failed; got: " +book .color );
333
+ } catch (InvalidFormatException e ) {
334
+ verifyException (e , "Cannot deserialize value of type " );
335
+ verifyException (e , "not one of the values accepted for Enum class" );
336
+ }
337
+ }
307
338
}
You can’t perform that action at this time.
0 commit comments