Support use of `@JsonAlias` for enum values
See original GitHub issueFeature request Would like to suggest the following feature. The enabling of @JsonAlias for enums.
Why? Enabling @JsonAlias for enums can help users that are faced with legacy properties.
Assume that version 0.1.0 has:
{
"key": "stringvalue"
}
and version 0.2.0 has:
{
"key": "stringValue"
}
Assume both are valid values and we want to map them to one Enum value. Having @JsonAlias available for this purpose can help to avoid bloat-code or custom de-serializers that do this.
Current behaviour Not implemented.
Expected behaviour I’d assume the same behaviour as with class members applies. So using @JsonProperty and @JsonAlias combined would yield the same result except for values not keys.
Example
public enum MyEnum{
@JsonProperty("stringvalue") //<- Value Jackson should use during serialization and de-serialization.
@JsonAlias({"stringValue"}) //<- Additional value, valid only during de-serialization.
STRING_VALUE //<- Would assume "string_value" is ignored and not added to the list of valid values
}
Extra information Version: 2.9 Occurs in patch: Yes Feature request was also mentioned in: this issue (Couldn’t find the accompanying Feature request)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:19 (10 by maintainers)
Excellent! I’ll add this to my work-in-progress list and hopefully have time to review tomorrow.
Big thanks to @RobertDiebels for contributing this & apologies for merging taking time. Will be nice addition to 2.11.