Enum Class EnumFormat
- All Implemented Interfaces:
Serializable,Comparable<EnumFormat>,Constable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionLower-case hyphenated form:MY_ENUM_VALUE→"my-enum-value".Lower-case underscored form:MY_ENUM_VALUE→"my_enum_value".CallsEnum.name()on the enum value.Sentinel meaning "no value configured" — falls through to the next-higher precedence level.Enum.ordinal()as a numeric value.CallsObject.toString()on the enum value (the default).Upper-case form usingLocale.ROOT: equivalent toEnum.name()for canonical UPPER_SNAKE enum names.Upper-case hyphenated form:MY_ENUM_VALUE→"MY-ENUM-VALUE". -
Method Summary
Modifier and TypeMethodDescriptionFormats the specified enum value using this format.booleanReturnstrue if this format is numeric on the wire.static <E extends Enum<E>>
EParses the specified wire value into an enum constant of the specified class.static EnumFormatReturns the enum constant of this class with the specified name.static EnumFormat[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NOT_SET
Sentinel meaning "no value configured" — falls through to the next-higher precedence level. -
TO_STRING
CallsObject.toString()on the enum value (the default). -
NAME
CallsEnum.name()on the enum value. -
LOWER_HYPHEN
Lower-case hyphenated form:MY_ENUM_VALUE→"my-enum-value". -
UPPER_HYPHEN
Upper-case hyphenated form:MY_ENUM_VALUE→"MY-ENUM-VALUE". -
LOWER_UNDERSCORE
Lower-case underscored form:MY_ENUM_VALUE→"my_enum_value". -
LOWER
-
UPPER
Upper-case form usingLocale.ROOT: equivalent toEnum.name()for canonical UPPER_SNAKE enum names. -
ORDINAL
Enum.ordinal()as a numeric value.
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
format
Formats the specified enum value using this format.- Parameters:
value- The enum value. Can benull (returnsnull ).- Returns:
- The formatted wire representation, or
null ifvalueisnull .
-
parse
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:- Numeric input → resolved as
ORDINAL. - Exact match against
Enum.name(). - Exact match against
Object.toString(). - Reconstruct UPPER_SNAKE form (replace
-with_, upper-case) and re-tryname(). - Case-insensitive match against
name()andtoString().
- Type Parameters:
E- The enum class type.- Parameters:
value- The wire value. Can benull or blank (returnsnull ).enumClass- The enum class. Must not benull .- Returns:
- The parsed enum constant, or
null ifvalueisnull or blank. - Throws:
IllegalArgumentException- If the value does not match any enum constant.
- Numeric input → resolved as
-
isNumeric
Returnstrue if this format is numeric on the wire.- Returns:
true if this format emits a numeric wire value.
-