Package com.google.gson
Enum ToNumberPolicy
- java.lang.Object
-
- java.lang.Enum<ToNumberPolicy>
-
- com.google.gson.ToNumberPolicy
-
- All Implemented Interfaces:
ToNumberStrategy
,java.io.Serializable
,java.lang.Comparable<ToNumberPolicy>
public enum ToNumberPolicy extends java.lang.Enum<ToNumberPolicy> implements ToNumberStrategy
An enumeration that defines two standard number reading strategies and a couple of strategies to overcome some historical Gson limitations while deserializing numbers asObject
andNumber
.- See Also:
ToNumberStrategy
-
-
Enum Constant Summary
Enum Constants Enum Constant Description BIG_DECIMAL
Using this policy will ensure that numbers will be read as numbers of arbitrary length usingBigDecimal
.DOUBLE
Using this policy will ensure that numbers will be read asDouble
values.LAZILY_PARSED_NUMBER
Using this policy will ensure that numbers will be read as a lazily parsed number backed by a string.LONG_OR_DOUBLE
Using this policy will ensure that numbers will be read asLong
orDouble
values depending on how JSON numbers are represented:Long
if the JSON number can be parsed as aLong
value, or otherwiseDouble
if it can be parsed as aDouble
value.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ToNumberPolicy
valueOf(java.lang.String name)
Returns 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, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Methods inherited from interface com.google.gson.ToNumberStrategy
readNumber
-
-
-
-
Enum Constant Detail
-
DOUBLE
public static final ToNumberPolicy DOUBLE
Using this policy will ensure that numbers will be read asDouble
values. This is the default strategy used during deserialization of numbers asObject
.
-
LAZILY_PARSED_NUMBER
public static final ToNumberPolicy 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
public static final ToNumberPolicy LONG_OR_DOUBLE
Using this policy will ensure that numbers will be read asLong
orDouble
values depending on how JSON numbers are represented:Long
if the JSON number can be parsed as aLong
value, or otherwiseDouble
if it can be parsed as aDouble
value. If the parsed double-precision number results in a positive or negative infinity (Double.isInfinite()
) or a NaN (Double.isNaN()
) value and theJsonReader
is notlenient
, aMalformedJsonException
is thrown.
-
BIG_DECIMAL
public static final ToNumberPolicy BIG_DECIMAL
Using this policy will ensure that numbers will be read as numbers of arbitrary length usingBigDecimal
.
-
-
Method Detail
-
values
public static ToNumberPolicy[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ToNumberPolicy c : ToNumberPolicy.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ToNumberPolicy valueOf(java.lang.String name)
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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
-