public final class JsonNumberUtils
extends java.lang.Object
Strings into Java numeric objects.| Modifier and Type | Method and Description |
|---|---|
static java.math.BigDecimal |
asBigDecimal(java.lang.String jsonNumberString)
Helper method for converting JSON number
Strings into BigDecimals. |
static java.math.BigInteger |
asBigInteger(java.lang.String jsonNumberString)
Helper method for converting JSON number
Strings into BigIntegers. |
static java.lang.Double |
asDouble(java.lang.String jsonNumberString)
Helper method for converting JSON number
Strings into Doubles. |
static java.lang.Integer |
asInteger(java.lang.String jsonNumberString)
Helper method for converting JSON number
Strings into Integers. |
public static java.math.BigDecimal asBigDecimal(java.lang.String jsonNumberString)
Strings into BigDecimals.jsonNumberString - a String representation of a JSON number.BigDecimal representing the given JSON number String.java.lang.NumberFormatException - if the given String is not a valid JSON number.public static java.math.BigInteger asBigInteger(java.lang.String jsonNumberString)
Strings into BigIntegers.jsonNumberString - a String representation of an integer JSON number.BigInteger representing the given JSON number String.java.lang.NumberFormatException - if the given String is not a valid JSON number or is not an integer.public static java.lang.Double asDouble(java.lang.String jsonNumberString)
Strings into Doubles. Note that use of this
method is risky as java Doubles have limited precision, whereas JSON numbers have unlimited
precision, i.e. converting a JSON number to a Double may result is a loss of accuracy.jsonNumberString - a String representation of an integer JSON number.Double representing the given JSON number String.java.lang.NumberFormatException - if the given String is not a valid JSON number.public static java.lang.Integer asInteger(java.lang.String jsonNumberString)
Strings into Integers. Note that use of this
method is risky as java Integers have limited precision (between Integer.MIN_VALUE and
Integer.MAX_VALUE) whereas JSON numbers have unlimited precision. This conversion is analogous to a
narrowing primitive conversion from long to int as defined in
The Java™ Language Specification: if this JSON number String is too big to fit in an
int, only the low-order 32 bits are returned. Note that this conversion can lose information about the
overall magnitude of the JSON number String value as well as return a result with the opposite sign.jsonNumberString - a String representation of an integer JSON number.Integer representing the given JSON number String.java.lang.NumberFormatException - if the given String is not a valid JSON number or is not an integer.