Enum Class EnumFormat

java.lang.Object
java.lang.Enum<EnumFormat>
org.apache.juneau.marshall.EnumFormat
All Implemented Interfaces:
Serializable, Comparable<EnumFormat>, Constable

public enum EnumFormat extends Enum<EnumFormat>
Supported wire formats for Enum values.

Used by MarshallingContext.Builder.enumFormat(EnumFormat), Marshalled.enumFormat(), MarshalledProp.enumFormat(), and MarshalledConfig.enumFormat() to control how Enum values are written to and read from the wire.

The default is TO_STRING which preserves the historical wire output produced by Object.toString() (the previous default before this enum existed). New APIs SHOULD prefer NAME for stability against toString() overrides.

Numeric formats (ORDINAL) emit native numeric wire types on binary serializers (BSON / CBOR / MsgPack) and a bare integer literal on text formats. All other constants emit a UTF-8 string.

Parsers SHALL accept any wire shape that the corresponding serializer can produce, regardless of the parser-side EnumFormat setting. The parser-side setting is consulted only for genuinely ambiguous input.

  • Enum Constant Details

  • Method Details

    • values

      public static EnumFormat[] 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 EnumFormat 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
    • format

      public String format(Enum<?> value)
      Formats the specified enum value using this format.
      Parameters:
      value - The enum value. Can be null (returns null).
      Returns:
      The formatted wire representation, or null if value is null.
    • parse

      public static <E extends Enum<E>> E parse(String value, Class<E> enumClass)
      Parses the specified wire value into an enum constant of the specified class.

      Parsing is format-agnostic: every constant accepts any of the wire shapes produced by format(Enum) regardless of the configured constant. Lookup order:

      1. Numeric input → resolved as ORDINAL.
      2. Exact match against Enum.name().
      3. Exact match against Object.toString().
      4. Reconstruct UPPER_SNAKE form (replace - with _, upper-case) and re-try name().
      5. Case-insensitive match against name() and toString().
      Type Parameters:
      E - The enum class type.
      Parameters:
      value - The wire value. Can be null or blank (returns null).
      enumClass - The enum class. Must not be null.
      Returns:
      The parsed enum constant, or null if value is null or blank.
      Throws:
      IllegalArgumentException - If the value does not match any enum constant.
    • isNumeric

      public boolean isNumeric()
      Returns true if this format is numeric on the wire.
      Returns:
      true if this format emits a numeric wire value.