-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
Apparently, disabling the FAIL_ON_INVALID_SUBTYPE feature has some (at least for me) unexpected side-effects on the deserialization of enums. I originally found this issue in jackson-databind 2.10.0, but it still exists in 2.11.0.
I have an enum that implements an interface:
@JsonTypeInfo(use = Id.NAME)
public interface CustomEnum {}
@JsonTypeName("Test")
public enum TestEnum implements CustomEnum {
VALUE;
}
Then, this test case works fine:
ObjectMapper mapper = new ObjectMapper();
mapper.registerSubtypes(TestEnum.class);
mapper.enable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE);
CustomEnum testValue = TestEnum.VALUE;
String json = mapper.writeValueAsString(testValue);
CustomEnum deserializedValue = mapper.readValue(json, CustomEnum.class);
assertEquals(testValue, deserializedValue);
However, when I disable the feature, the test case fails because deserializedValue
is suddenly null
. The reason seems to be that a NullyfingDeserializer
is returned from TypeDeserializerBase._findDefaultImplDeserializer(...)
instead of null
. Therefore, the AsPropertyDeserializer
no longer tries to read the value itself.
kpuranik-jama
Metadata
Metadata
Assignees
Labels
No labels