File tree Expand file tree Collapse 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 Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ Project: jackson-databind
2525 (fix by Joo-Hyuk K)
2626#4450: Empty QName deserialized as `null`
2727 (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)
2831
29322.17.0 (12-Mar-2024)
3033
Original file line number Diff line number Diff line change @@ -486,8 +486,10 @@ protected CompactStringObjectMap _getToStringLookup(DeserializationContext ctxt)
486486
487487 // @since 2.15
488488 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 );
491493 }
492494
493495 // @since 2.15
Original file line number Diff line number Diff line change @@ -93,6 +93,16 @@ enum MyEnum2352_3 {
9393 C ;
9494 }
9595
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+
96106 /*
97107 /**********************************************************
98108 /* Test methods, basic
@@ -304,4 +314,25 @@ public void testEnumWithNullForUnknownValueEnumSet() throws Exception {
304314 assertEquals (1 , pojo .value .size ());
305315 assertTrue (pojo .value .contains (MyEnum2352_3 .B ));
306316 }
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+ }
307338}
You can’t perform that action at this time.
0 commit comments