jackson-annotations
jackson-annotations copied to clipboard
Document that @JsonAlias can be used on enum values
https://github.com/FasterXML/jackson-databind/issues/2352 added support for using @JsonAlias to accept alternate enum values. However, this functionality is not documented in the @JsonAlias Javadocs. It was therefore quite the surprise to me to discover this was a valid usage.
I believe the Javadocs should be updated to document this case.
Examples in other annotations that change enum values in addition to a separate primary usage:
NOTE: when use for Java
enums, one additional feature is that value returned by annotated method is also considered to be the value to deserialize from, not just JSON String to serialize as. This is possible since set of Enum values is constant and it is possible to define mapping, but can not be done in general for POJO types; as such, this is not used for POJO deserialization.
Starting with Jackson 2.6 this annotation may also be used to change serialization of
Enumlike so:public enum MyEnum { @JsonProperty("theFirstValue") THE_FIRST_VALUE, @JsonProperty("another_value") ANOTHER_VALUE; }as an alternative to using
JsonValueannotation.
Agreed, this would make sense. PRs welcome!