Skip to content

Add SerializationFeature.WRITE_ENUM_KEYS_USING_INDEX, separate from value setting #2129

Closed
@renzihui

Description

@renzihui

A new feature to "revert" behavior change in #1570

e.g. define a new SerializationFeature.WRITE_MAP_KEY_ENUMS_USING_INDEX (or whatever you think is appropriate), when it is set to false while SerializationFeature.WRITE_ENUMS_USING_INDEX is true, enum values are serialised as int (enum ordinal), enum key are serialised as string(enum name)

Why need this:

  1. Json's key is always string type, it is counterintuitive to write enum to a string of number
  2. Compatibility, many json library are unable to deserialize Map<Enum, Object> from this style {"n_index","any"}, including current Jackson see Deserialize Enums using ordinal does not work for map keys #1877

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