Fallback Default Value for Enum Type Field
See original GitHub issueIs your feature request related to a problem? Please describe. jackson-databind: 2.11.4
Hi, I was trying to deserialize json to Kotlin data class object which includes enum type field.
But since the value of the corresponding json field is not one of the enum values, it throws InvalidFormatException
data class A(
val type: EnumType
...
) : Serializable
However, I don’t need values other than the ones that are already of the enum values. So I want to set the field of the object as the default value if the value from the json does not match with any of the enum values. I think there’s no way this can be done as far as I have searched.
Describe the solution you’d like Annotation that sets default value as fallback on a field of a serialzable object
Usage example
data class A(
@DeserializeEnumDefault(EnumType.TypeA)
val type: EnumType
...
) : Serializable
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Choosing the default value of an Enum type without having to ...
The default value for an enumeration type is 0: "By default, the first enumerator has the value 0, and the value of each...
Read more >Jackson JSON - Using @JsonEnumDefaultValue to ... - LogicBig
JsonEnumDefaultValue annotation can be used on an enum element to define a default (fallback) value used during deserialize.
Read more >Assigning a default value if one doesnt exist in enum - Support
I wanted to know if it was possible to set a default value for a enum class if a value doesn't exist in...
Read more >Safety Considerations When Using Enums in Avro Schemas
Here we specify two defaults: A field default — informs a reader to use the default value if the field is not present...
Read more >3107-derive-default-enum - The Rust RFC Book
The ability to add default values to fields of enum variants does not mean that you can suddenly #[derive(Default)] on the enum. A...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ko-ing I am very glad it worked out once you found the problem. Thank you for confirming!
Thanks for your gentle answer!
It turned out that it was my mistake to only implement the object mapper on the encoder of webclient. I managed to add this configuration and works fine for me!
I’ll close this issue Have a good day!