Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mjustin opened this issue Oct 26, 2021 · 3 comments
Closed

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

mjustin opened this issue Oct 26, 2021 · 3 comments
Labels
documentation good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project

Comments

@mjustin
Copy link

mjustin commented Oct 26, 2021

FasterXML/jackson-databind#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
Copy link
Member

cowtowncoder commented Oct 26, 2021

Agreed, this would make sense. PRs welcome!

@cowtowncoder cowtowncoder added documentation good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project labels Oct 26, 2021
@mukham12
Copy link
Contributor

Hi @cowtowncoder,

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

@cowtowncoder
Copy link
Member

Yes, will close thank you @mukham12 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project
Projects
None yet
Development

No branches or pull requests

3 participants