Skip to content

Add @EnumNaming, EnumNamingStrategy to allow use of naming strategies for Enums #2667

@cowtowncoder

Description

@cowtowncoder

As things are, the only way to change representation of Enum values (which defaults to using Enum.name()) is to use either "use toString()" or explicit @JsonProperty overrides.
But it appears that there is usage where there is naming convention in use, similar to how @JsonNaming works mapping POJO fields to external JSON property names.

One possibility might be to try to directly support use of @JsonNaming on Enum classes.
This may or may not be practical, considering underlying PropertyNamingStrategy is tied to accessors (Field, Method) that POJOs expose -- but bigger issue may be that this would be two-dimensional mapping as unlike POJO property names that use Bean naming ([lower] camel case), Enum names themselves may use one convention, and external names another one.
As such it may be necessary to either come up with new abstraction(s), or maybe just alternate PropertyNamingStrategy implementations.

NOTE: implementation adds

  • @EnumNaming annotation
  • with EnumNamingStrategy (for strategy implementations)
  • EnumNamingStrategies container for a set of out-of-the-box EnumNamingStrategy implementations
    • For 2.15, only CamelCaseStrategy added -- replaced in 2.19 with LowerCamelCaseStrategy

Jackson 2.19 will further add a large set of new strategy implementations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enumRelated to handling of Enum valuesmost-wantedTag to indicate that there is heavy user +1'ing action

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions