Package com.google.gson
Enum ToNumberPolicy
- All Implemented Interfaces:
ToNumberStrategy,Serializable,Comparable<ToNumberPolicy>,java.lang.constant.Constable
An enumeration that defines two standard number reading strategies and a couple of
strategies to overcome some historical Gson limitations while deserializing numbers as
Object and Number.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionUsing this policy will ensure that numbers will be read as numbers of arbitrary length usingBigDecimal.Using this policy will ensure that numbers will be read asDoublevalues.Using this policy will ensure that numbers will be read as a lazily parsed number backed by a string. -
Method Summary
Modifier and TypeMethodDescriptionstatic ToNumberPolicyReturns the enum constant of this type with the specified name.static ToNumberPolicy[]values()Returns an array containing the constants of this enum type, in the order they are declared.Methods inherited from class java.lang.Enum
compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOfMethods inherited from interface com.google.gson.ToNumberStrategy
readNumber
-
Enum Constant Details
-
DOUBLE
-
LAZILY_PARSED_NUMBER
Using this policy will ensure that numbers will be read as a lazily parsed number backed by a string. This is the default strategy used during deserialization of numbers asNumber. -
LONG_OR_DOUBLE
Using this policy will ensure that numbers will be read asLongorDoublevalues depending on how JSON numbers are represented:Longif the JSON number can be parsed as aLongvalue, or otherwiseDoubleif it can be parsed as aDoublevalue. If the parsed double-precision number results in a positive or negative infinity (Double.isInfinite()) or a NaN (Double.isNaN()) value and theJsonReaderis notlenient, aMalformedJsonExceptionis thrown. -
BIG_DECIMAL
Using this policy will ensure that numbers will be read as numbers of arbitrary length usingBigDecimal.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException- if the argument is null
-