Enum Class BigNumberFormat
- All Implemented Interfaces:
Serializable,Comparable<BigNumberFormat>,Constable
BigInteger and BigDecimal values.
Used by MarshallingContext.Builder.bigNumberFormat(BigNumberFormat),
Marshalled.bigNumberFormat(),
MarshalledProp.bigNumberFormat(), and
MarshalledConfig.bigNumberFormat() to control how
BigInteger / BigDecimal values are written to text-based wire formats.
The default is NUMBER which preserves the historical wire output (a bare numeric token).
JS-interop motivation
JavaScript's Number.MAX_SAFE_INTEGER is 2^53 − 1 (= 9007199254740991).
Values outside that range silently lose precision when parsed by a JavaScript client. STRING
forces a quoted-string representation that round-trips losslessly. AUTO picks NUMBER
for values that are JS-safe and STRING for everything else — the typical "safe default" for
services that may be consumed by both JVM and browser clients.
Precedence (highest to lowest)
@MarshalledProp(bigNumberFormat=…)on the bean property.@Marshalled(bigNumberFormat=…)on the bean class.@MarshalledConfig(bigNumberFormat=…)on-annotated classes / methods.@Rest - Programmatic
MarshallingContext.Builder.bigNumberFormat(BigNumberFormat). - Environment variable
MarshallingContext.bigNumberFormat . - The default constant (
NUMBER).
Parser leniency
Parsers SHALL accept both bare numeric and quoted-string input regardless of the parser-side
BigNumberFormat setting. The configured constant is informational only.
Binary serializers
Binary serializers (BSON / CBOR / MsgPack / Prototext) emit native numeric types regardless of the
configured BigNumberFormat; this setting only affects text-based serializers. BSON has
decimal128 for exact decimal values; CBOR / MsgPack handle big-integer values via
tag 2 / tag 3 with string fallback.
-
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.Bare numeric token (the default).Quoted-string form for lossless precision. -
Method Summary
Modifier and TypeMethodDescriptionstatic Objectformat(BigDecimal value, BigNumberFormat format) Formats the specifiedBigDecimalusing this format.static Objectformat(BigInteger value, BigNumberFormat format) Formats the specifiedBigIntegerusing this format.booleanReturnstrue if this format always emits a numeric wire value.static <T extends Number>
Tparse(String value, BigNumberFormat format, Class<T> targetType) Parses the specified wire value into aBigIntegerorBigDecimal.static BigNumberFormatReturns the enum constant of this class with the specified name.static BigNumberFormat[]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. -
NUMBER
Bare numeric token (the default).Example:
12345678901234567890
This is the historical wire output and the natural form for server-to-server JVM clients.
-
STRING
Quoted-string form for lossless precision.Example:
"12345678901234567890"
Round-trips losslessly through any JSON / YAML / etc. parser, including JavaScript clients which would otherwise truncate to a 64-bit double.
-
AUTO
Hybrid — emitNUMBERwhen the value is JS-safe (fits in±(2^53 − 1)), otherwise emitSTRING.For
BigDecimalvalues, any non-zero scale forcesSTRING(a fractional value cannot be safely represented in a JS double regardless of magnitude).The "safe default" for services that may be consumed by both JVM and browser clients.
-
-
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 specifiedBigIntegerusing this format.Returns either a
Number(whenNUMBERorAUTOproduces a JS-safe value) or aString(whenSTRINGorAUTOproduces an out-of-range value). Callers should branch on the runtime type:- Parameters:
value- The value to format. Can benull (returnsnull ).format- The configured format. Can benull (treated asNUMBER).- Returns:
- The formatted value (a
BigIntegerfor numeric output, aStringfor string output), ornull ifvalueisnull .
-
format
Formats the specifiedBigDecimalusing this format.Returns either a
Number(whenNUMBERorAUTOproduces a JS-safe value) or aString(whenSTRINGorAUTOproduces an out-of-range value).For
AUTO: any non-zero-scaleBigDecimal(i.e. has a fractional part) forcesSTRINGsince fractional values cannot be safely represented in a JS double regardless of magnitude. Zero-scale values are tested against the integer±(2^53 − 1)bound.- Parameters:
value- The value to format. Can benull (returnsnull ).format- The configured format. Can benull (treated asNUMBER).- Returns:
- The formatted value (a
BigDecimalfor numeric output, aStringfor string output), ornull ifvalueisnull .
-
parse
Parses the specified wire value into aBigIntegerorBigDecimal.Accepts both bare numeric and quoted-string input regardless of the
formathint. The hint is informational only.- Type Parameters:
T- The target type (BigIntegerorBigDecimal).- Parameters:
value- The wire value. Can benull or blank (returnsnull ).format- The configured format (informational only — parsing is format-agnostic). Can benull (ignored; parsing is format-agnostic).targetType- The desired return type —BigIntegerorBigDecimal.- Returns:
- The parsed value, or
null ifvalueisnull or blank. - Throws:
IllegalArgumentException- If the value cannot be parsed as a number ortargetTypeis unsupported.
-
isNumeric
Returnstrue if this format always emits a numeric wire value.NUMBERreturnstrue ;STRINGreturnsfalse .AUTOreturnsfalse conservatively — itsformat(...)return type varies per value, so serializers should branch on the actual runtime type returned byformat(BigInteger, BigNumberFormat)/format(BigDecimal, BigNumberFormat)rather than this hint.- Returns:
true if this format emits a bare numeric wire value.
-