jackson-annotations icon indicating copy to clipboard operation
jackson-annotations copied to clipboard

Document that @JsonAlias can be used on enum values

Open mjustin opened this issue 4 years ago • 1 comments

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:

@JsonValue:

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.

@JsonProperty:

Starting with Jackson 2.6 this annotation may also be used to change serialization of Enum like so:

public enum MyEnum {
     @JsonProperty("theFirstValue") THE_FIRST_VALUE,
     @JsonProperty("another_value") ANOTHER_VALUE;
}

as an alternative to using JsonValue annotation.

mjustin avatar Oct 26 '21 06:10 mjustin

Agreed, this would make sense. PRs welcome!

cowtowncoder avatar Oct 26 '21 17:10 cowtowncoder