Enum Class EnumFeature

java.lang.Object
java.lang.Enum<EnumFeature>
tools.jackson.databind.cfg.EnumFeature
All Implemented Interfaces:
Serializable, Comparable<EnumFeature>, Constable, JacksonFeature, DatatypeFeature

public enum EnumFeature extends Enum<EnumFeature> implements DatatypeFeature
New Datatype-specific configuration options related to handling of Enum types.
  • Enum Constant Details

    • READ_ENUM_KEYS_USING_INDEX

      public static final EnumFeature READ_ENUM_KEYS_USING_INDEX
      Feature that determines standard deserialization mechanism used for Enum values: if enabled, Enums are assumed to have been serialized using index of Enum;

      Note: this feature should be symmetric to as WRITE_ENUM_KEYS_USING_INDEX.

      Feature is disabled by default.

      Since:
      2.15
    • FAIL_ON_NUMBERS_FOR_ENUMS

      public static final EnumFeature FAIL_ON_NUMBERS_FOR_ENUMS
      Feature that determines whether JSON integer numbers are valid values to be used for deserializing Java enum values. If set to 'false' numbers are acceptable and are used to map to ordinal() of matching enumeration value; if 'true', numbers are not allowed and a DatabindException will be thrown. Latter behavior makes sense if there is concern that accidental mapping from integer values to enums might happen (and when enums are always serialized as JSON Strings)

      Feature used to be one of DeserializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is disabled by default.

    • READ_ENUMS_USING_TO_STRING

      public static final EnumFeature READ_ENUMS_USING_TO_STRING
      Feature that determines the deserialization mechanism used for Enum values: if enabled, Enums are assumed to have been serialized using return value of Enum.toString(); if disabled, return value of Enum.name() is assumed to have been used.

      Note: this feature should usually have same value as WRITE_ENUMS_USING_TO_STRING.

      Feature used to be one of DeserializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is enabled by default as of Jackson 3.0 (in 2.x it was disabled).

    • READ_UNKNOWN_ENUM_VALUES_AS_NULL

      public static final EnumFeature READ_UNKNOWN_ENUM_VALUES_AS_NULL
      Feature that allows unknown Enum values to be parsed as null values. If disabled, unknown Enum values will throw exceptions.

      Note that in some cases this will effectively ignore unknown Enum values, e.g. when the unknown values are used as keys of EnumMap or values of EnumSet: this is because these data structures cannot store null values.

      Also note that this feature has lower precedence than READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, meaning this feature will work only if latter feature is disabled.

      Feature used to be one of DeserializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is disabled by default.

    • READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE

      public static final EnumFeature READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE
      Feature that allows unknown Enum values to be ignored and replaced by a predefined value specified through @JsonEnumDefaultValue annotation. If disabled, unknown Enum values will throw exceptions. If enabled, but no predefined default Enum value is specified, an exception will be thrown as well.

      Note that this feature has higher precedence than READ_UNKNOWN_ENUM_VALUES_AS_NULL.

      Feature used to be one of DeserializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is disabled by default.

    • WRITE_ENUMS_TO_LOWERCASE

      public static final EnumFeature WRITE_ENUMS_TO_LOWERCASE
      Feature that determines standard serialization mechanism used for Enum values: if enabled, return value of Enum.name().toLowerCase() is used; if disabled, return value of Enum.name() is used.

      NOTE: this feature CANNOT be changed on per-call basis: it will have to be set on ObjectMapper before use

      Feature is disabled by default.

      Since:
      2.15
    • WRITE_ENUMS_USING_TO_STRING

      public static final EnumFeature WRITE_ENUMS_USING_TO_STRING
      Feature that determines standard serialization mechanism used for Enum values: if enabled, return value of Enum.toString() is used; if disabled, return value of Enum.name() is used.

      Note: this feature should usually have same value as READ_ENUMS_USING_TO_STRING.

      Feature used to be one of SerializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is enabled by default as of Jackson 3.0 (in 2.x it was disabled).

    • WRITE_ENUMS_USING_INDEX

      public static final EnumFeature WRITE_ENUMS_USING_INDEX
      Feature that determines whether Java Enum values are serialized as numbers (true), or textual values (false). If textual values are used, other settings are also considered. If this feature is enabled, return value of Enum.ordinal() (an integer) will be used as the serialization.

      Note that this feature has precedence over WRITE_ENUMS_USING_TO_STRING, which is only considered if this feature is set to false.

      Note that since 2.10, this does NOT apply to Enums written as keys of Map values, which has separate setting, WRITE_ENUM_KEYS_USING_INDEX.

      Feature used to be one of SerializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is disabled by default.

    • WRITE_ENUM_KEYS_USING_INDEX

      public static final EnumFeature WRITE_ENUM_KEYS_USING_INDEX
      Feature that determines whether {link Enum}s used as Map keys are serialized as using Enum.ordinal() or not. Similar to WRITE_ENUMS_USING_INDEX used when writing Enums as regular values.

      NOTE: counterpart for this settings is READ_ENUM_KEYS_USING_INDEX.

      Feature used to be one of SerializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is disabled by default.

  • Method Details

    • values

      public static EnumFeature[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static EnumFeature valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • enabledByDefault

      public boolean enabledByDefault()
      Specified by:
      enabledByDefault in interface JacksonFeature
    • enabledIn

      public boolean enabledIn(int flags)
      Specified by:
      enabledIn in interface JacksonFeature
    • getMask

      public int getMask()
      Specified by:
      getMask in interface JacksonFeature
    • featureIndex

      public int featureIndex()
      Description copied from interface: DatatypeFeature
      Internal index used for efficient storage and index; no user serviceable contents inside!
      Specified by:
      featureIndex in interface DatatypeFeature