You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With this ObjectMapper, when one attempts to deserialize an enum value V for an enum with an @JsonEnumDefaultValue element, the deserialization will:
Pass, if V is a valid enum value. ✅
Pass, if V is an invalid non-integer value. ✅
Fail, if V is an invalid integer value. ❌
To me this seems highly unintuitive. I would have expected the READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE feature to take precedence over the FAIL_ON_NUMBERS_FOR_ENUMS feature in those cases where it applies (i.e., when deserializing an enum with a default element).
I've put together a test class enumerating the relevant cases. See the inline comments towards the bottom. In four cases I feel that Jackson's current behavior is not as one might expect.
Thank you for reporting this, providing comprehensive tests! I'll have a look; I assume you are right unless I find something to suggest otherwise, and see if I can change behavior as requested.
Yes, I agree. Handling of "number as string" is bit odd altogether, so I changed it to only be tried unless failure would occur; either way given tests pass and behavior is improved, I agree.
Super. Thanks for the rapid fix! I'll keep in mind to use the test format in EnumDefaultReadTest.java next time around. (Though hopefully there'll be no next time around ;).)
Consider the following
ObjectMapper
definition:With this
ObjectMapper
, when one attempts to deserialize an enum value V for an enum with an@JsonEnumDefaultValue
element, the deserialization will:To me this seems highly unintuitive. I would have expected the
READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE
feature to take precedence over theFAIL_ON_NUMBERS_FOR_ENUMS
feature in those cases where it applies (i.e., when deserializing an enum with a default element).I've put together a test class enumerating the relevant cases. See the inline comments towards the bottom. In four cases I feel that Jackson's current behavior is not as one might expect.
Would love to hear your thoughts on this. (If there is some other feature I should enable to get the behavior I'm looking for, let me know :).)
The text was updated successfully, but these errors were encountered: