FasterXML / jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
https://github.com/FasterXML/jackson
Apache License 2.0
1.03k stars 330 forks source link

Document that @JsonAlias can be used on enum values #193

Closed mjustin closed 1 year ago

mjustin commented 3 years ago

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.

cowtowncoder commented 3 years ago

Agreed, this would make sense. PRs welcome!

mukham12 commented 1 year ago

Hi @cowtowncoder,

Can this be closed now that the requested change is merged?

cowtowncoder commented 1 year ago

Yes, will close thank you @mukham12 !