Skip to content

Support use of @JsonAlias for enum values #2352

@RobertDiebels

Description

@RobertDiebels

Feature 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions