Enum Class FloatFormat
- All Implemented Interfaces:
Serializable,Comparable<FloatFormat>,Constable
Float / Double values
(NaN, +Infinity, -Infinity).
Used by MarshallingContext.Builder.floatFormat(FloatFormat),
Marshalled.floatFormat(),
MarshalledProp.floatFormat(), and
MarshalledConfig.floatFormat() to control how non-finite
floating-point values are written to text-based wire formats. Finite values are unaffected and ride
the natural bare-numeric-token wire form for the underlying serializer.
The default is NaN_AS_NULL which is JSON-spec-compliant per RFC 8259 §6 (non-finite floats
are not valid JSON tokens; emitting null is the closest valid representation).
Precedence (highest to lowest)
@MarshalledProp(floatFormat=…)on the bean property.@Marshalled(floatFormat=…)on the bean class.@MarshalledConfig(floatFormat=…)on-annotated classes / methods.@Rest - Programmatic
MarshallingContext.Builder.floatFormat(FloatFormat). - Environment variable
MarshallingContext.floatFormat . - The default constant (
NaN_AS_NULL).
Parser leniency
Parsers SHALL accept all of the following wire shapes regardless of the parser-side
FloatFormat setting:
- Bare numeric tokens including the non-standard
NaN/Infinity/-Infinitytokens (Juneau's lenient parser accepts these by default). - Quoted-string forms —
"NaN","Infinity","-Infinity"(case-insensitive). null— reconstructed asDouble.NaNwhen reading into a primitivedouble/float; preserved asnullwhen reading into a boxedDouble/Float.
JSON-spec compliance
NaN_AS_NUMBER is non-standard JSON per RFC 8259 §6 — JSON does not permit NaN /
Infinity / -Infinity tokens. Juneau's own JSON parser accepts these in lenient mode,
but strict-mode consumers (e.g. some browser JSON.parse pipelines) will reject them. Use only
when you control both ends of the wire.
Binary serializers
Binary serializers (BSON / CBOR / MsgPack / Prototext / Parquet) emit native IEEE-754 floats regardless
of this setting; native non-finite representations exist in every supported binary format (BSON
double / decimal128; CBOR's tag 22 / 23 / 24 for special floats; MsgPack float64).
This setting only affects text-based serializers.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThrowIllegalArgumentExceptionwhen a non-finite value is encountered.EmitnullforNaN/±Infinity(the default).Emit the bareNaN/Infinity/-Infinitytoken.Emit the quoted string"NaN"/"Infinity"/"-Infinity".Sentinel meaning "no value configured" — falls through to the next-higher precedence level. -
Method Summary
Modifier and TypeMethodDescriptionstatic Objectformat(double value, FloatFormat format) Formats the specifieddoubleusing this format.static Objectformat(float value, FloatFormat format) Formats the specifiedfloatusing this format.booleanReturnstrue if this format always emits a bare numeric wire token for non-finite values.static <T extends Number>
Tparse(String value, FloatFormat format, Class<T> targetType) static FloatFormatReturns the enum constant of this class with the specified name.static FloatFormat[]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. -
NaN_AS_NULL
EmitnullforNaN/±Infinity(the default).JSON-spec compliant. Loses the ability to distinguish
NaNfrom+Infinityfrom-Infinityon the wire — all three becomenull. Round-trips back toDouble.NaNwhen reading into a primitivedouble; into a boxedDoublefield,nullstaysnull. -
NaN_AS_STRING
Emit the quoted string"NaN"/"Infinity"/"-Infinity".Round-trip preserving. The parser unambiguously decodes the string back to the original non-finite value.
-
NaN_AS_NUMBER
Emit the bareNaN/Infinity/-Infinitytoken.Non-standard JSON per RFC 8259 §6. Accepted by Juneau's lenient parser and V8 / several Python libs; rejected by strict consumers. Use only when you control both ends of the wire.
-
NaN_AS_ERROR
ThrowIllegalArgumentExceptionwhen a non-finite value is encountered.Fail-fast for data-cleanliness pipelines where a
NaNindicates upstream corruption.
-
-
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 specifieddoubleusing this format.Finite values always return the boxed
Doubleso text serializers emit the bare numeric token. Non-finite values are dispatched per the constant:NaN_AS_NULL→null.NaN_AS_STRING→"NaN"/"Infinity"/"-Infinity".NaN_AS_NUMBER→ boxedDouble(non-finite); text serializers emit the bare token.NaN_AS_ERROR→ throwsIllegalArgumentException.
NOT_SET/nullformat are treated asNaN_AS_NULL.- Parameters:
value- The value to format.format- The configured format. Can benull (treated asNaN_AS_NULL).- Returns:
- The formatted value — a
Doublefor finite orNaN_AS_NUMBER, aStringforNaN_AS_STRING, ornullfor non-finite underNaN_AS_NULL. - Throws:
IllegalArgumentException- IfformatisNaN_AS_ERRORand the value is non-finite.
-
format
Formats the specifiedfloatusing this format.Finite values return the boxed
Float. Non-finite values follow the same rules asformat(double, FloatFormat)except thatNaN_AS_NUMBERreturns the boxedFloat(notDouble).- Parameters:
value- The value to format.format- The configured format. Can benull (treated asNaN_AS_NULL).- Returns:
- The formatted value — a
Floatfor finite orNaN_AS_NUMBER, aStringforNaN_AS_STRING, ornullfor non-finite underNaN_AS_NULL. - Throws:
IllegalArgumentException- IfformatisNaN_AS_ERRORand the value is non-finite.
-
parse
Parses the specified wire value into a non-finite-awareDoubleorFloat.Lenient parsing — accepts bare numeric, quoted-string
"NaN"/"Infinity"/"-Infinity"(case-insensitive), and unquotedNaN/Infinity/-Infinitytokens regardless of theformathint. The hint is informational only.- Type Parameters:
T- The target type (DoubleorFloat).- Parameters:
value- The wire value. Can benull or blank (returnsnull ).format- The configured format hint (informational only — parsing is format-agnostic). Can benull (ignored; parsing is format-agnostic).targetType- The desired return type —DoubleorFloat.- Returns:
- The parsed value, or
null ifvalueisnull or blank. - Throws:
IllegalArgumentException- If the value cannot be parsed ortargetTypeis unsupported.
-
isNumeric
Returnstrue if this format always emits a bare numeric wire token for non-finite values.Only
NaN_AS_NUMBERreturnstrue .NaN_AS_NULLmay emitnull;NaN_AS_STRINGemits a quoted string;NaN_AS_ERRORthrows. Finite values are always emitted as bare numeric tokens regardless of this setting.- Returns:
true if this format emits a bare numeric wire token for non-finite values.
-