Enum Class BooleanFormat

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

public enum BooleanFormat extends Enum<BooleanFormat>
Supported wire formats for 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 true / false tokens).

Precedence (highest to lowest)
  1. @MarshalledProp(booleanFormat=…) on the bean property.
  2. @Marshalled(booleanFormat=…) on the bean class.
  3. @MarshalledConfig(booleanFormat=…) on @Rest-annotated classes / methods.
  4. Programmatic MarshallingContext.Builder.booleanFormat(BooleanFormat).
  5. Environment variable MarshallingContext.booleanFormat.
  6. 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 0 / 1 (not the string "0" / "1") so the wire shape matches an int field.

  • Enum Constant Details

    • NOT_SET

      public static final BooleanFormat NOT_SET
      Sentinel meaning "no value configured" — falls through to the next-higher precedence level.
    • TRUE_FALSE

      public static final BooleanFormat TRUE_FALSE
      Standard boolean tokens (the default).
      Example:

      true false

      Round-trips through Boolean.toString() / Boolean.parseBoolean(String).

    • ZERO_ONE

      public static final BooleanFormat ZERO_ONE
      Numeric tokens — 0 for false and 1 for true.
      Example:

      1 0

      JSON / JSON5 emit the bare numeric token 0 / 1 (not the quoted string "0" / "1") so the wire shape matches an int field. Useful for CSV-shaped JSON consumers and SQL-style payloads.

    • YES_NO

      public static final BooleanFormat YES_NO
      English long-form yes / no.
      Example:

      yes no

      Common in human-friendly CSV and form-encoded payloads.

    • Y_N

      public static final BooleanFormat Y_N
      Compact single-character yes / no.
      Example:

      Y N

      Compact single-character form, common in DB and CSV exports.

    • ON_OFF

      public static final BooleanFormat ON_OFF
      On / off.
      Example:

      on off

      Common in config files (HOCON / INI / TOML) and HTML form checkboxes.

  • Method Details

    • values

      public static BooleanFormat[] 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 BooleanFormat 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 static Object format(boolean value, BooleanFormat format)
      Formats the specified boolean using this format.

      The return type varies per constant:

      NOT_SET falls through to TRUE_FALSE.

      Parameters:
      value - The value to format.
      format - The configured format. Can be null (treated as TRUE_FALSE).
      Returns:
      The formatted wire value — a Boolean, Integer, or String depending on the format.
    • parse

      public static boolean parse(String value, BooleanFormat format)
      Parses the specified wire value into a primitive boolean.

      Lenient parsing — accepts any of the textual shapes (true/false, 1/0, yes/no, y/n, on/off) regardless of the format hint, case-insensitive. The hint is informational only.

      Parameters:
      value - The wire value. Must not be null or blank, or an IllegalArgumentException is thrown.
      format - The configured format hint (informational only — parsing is format-agnostic). Can be null (ignored; parsing is format-agnostic).
      Returns:
      The parsed boolean value.
      Throws:
      IllegalArgumentException - If value is null, blank, or does not match any supported boolean textual shape.
    • isNumeric

      public boolean isNumeric()
      Returns true if this format always emits a numeric wire token.

      ZERO_ONE returns true; every other constant returns false. Note that TRUE_FALSE emits 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.