Enum Class BooleanFormat
- All Implemented Interfaces:
Serializable,Comparable<BooleanFormat>,Constable
Boolean / boolean values.
Used by MarshallingContext.Builder.booleanFormat(BooleanFormat),
Marshalled.booleanFormat(),
MarshalledProp.booleanFormat(), and
MarshalledConfig.booleanFormat() to control how boolean values
are written to text-based wire formats.
The default is TRUE_FALSE which preserves the historical wire output (the bare
Precedence (highest to lowest)
@MarshalledProp(booleanFormat=…)on the bean property.@Marshalled(booleanFormat=…)on the bean class.@MarshalledConfig(booleanFormat=…)on-annotated classes / methods.@Rest - Programmatic
MarshallingContext.Builder.booleanFormat(BooleanFormat). - Environment variable
MarshallingContext.booleanFormat . - The default constant (
TRUE_FALSE).
Parser leniency
Parsers SHALL accept any of the textual shapes (true/false, 1/0,
yes/no, y/n, on/off) regardless of the parser-side
BooleanFormat setting. Matching is case-insensitive. The configured constant is informational only.
Binary serializers
Binary serializers (BSON / CBOR / MsgPack / Prototext / Parquet) emit a native boolean wire type regardless
of this setting; the setting only affects text-based serializers (JSON / XML / CSV / HOCON / TOML / etc.).
For ZERO_ONE, JSON / JSON5 emit the bare numeric token field.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionSentinel meaning "no value configured" — falls through to the next-higher precedence level.On / off.Standard boolean tokens (the default).Compact single-character yes / no.English long-form yes / no.Numeric tokens —0 forfalseand1 fortrue. -
Method Summary
Modifier and TypeMethodDescriptionstatic Objectformat(boolean value, BooleanFormat format) Formats the specified boolean using this format.booleanReturnstrue if this format always emits a numeric wire token.static booleanparse(String value, BooleanFormat format) Parses the specified wire value into a primitiveboolean.static BooleanFormatReturns the enum constant of this class with the specified name.static BooleanFormat[]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. -
TRUE_FALSE
Standard boolean tokens (the default).Example:
true false
Round-trips through
Boolean.toString()/Boolean.parseBoolean(String). -
ZERO_ONE
Numeric tokens —0 forfalseand1 fortrue.Example:
1 0
JSON / JSON5 emit the bare numeric token
0 /1 (not the quoted string"0" /"1" ) so the wire shape matches anfield. Useful for CSV-shaped JSON consumers and SQL-style payloads.int -
YES_NO
English long-form yes / no.Example:
yes no
Common in human-friendly CSV and form-encoded payloads.
-
Y_N
Compact single-character yes / no.Example:
Y N
Compact single-character form, common in DB and CSV exports.
-
ON_OFF
On / off.Example:
on off
Common in config files (HOCON / INI / TOML) and HTML form checkboxes.
-
-
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 boolean using this format.The return type varies per constant:
TRUE_FALSE→Boolean(so JSON / XML emit the baretrue/falsetoken).ZERO_ONE→Integer(so JSON emits the bare numeric token0/1).YES_NO/Y_N/ON_OFF→String.
NOT_SETfalls through toTRUE_FALSE.- Parameters:
value- The value to format.format- The configured format. Can benull (treated asTRUE_FALSE).- Returns:
- The formatted wire value — a
Boolean,Integer, orStringdepending on the format.
-
parse
Parses the specified wire value into a primitiveboolean.Lenient parsing — accepts any of the textual shapes (
true/false,1/0,yes/no,y/n,on/off) regardless of theformathint, case-insensitive. The hint is informational only.- Parameters:
value- The wire value. Must not benull or blank, or anIllegalArgumentExceptionis thrown.format- The configured format hint (informational only — parsing is format-agnostic). Can benull (ignored; parsing is format-agnostic).- Returns:
- The parsed boolean value.
- Throws:
IllegalArgumentException- Ifvalueisnull , blank, or does not match any supported boolean textual shape.
-
isNumeric
Returnstrue if this format always emits a numeric wire token.ZERO_ONEreturnstrue ; every other constant returnsfalse . Note thatTRUE_FALSEemits a native boolean token (not a string) in JSON / XML — that is considered a boolean-typed wire value, not a numeric one.- Returns:
true if this format emits a bare numeric wire token.
-