Add SerializationFeature.WRITE_ENUM_KEYS_USING_INDEX, separate from value setting · Issue #2129 · FasterXML/jackson-databind (original) (raw)

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