public final class JsonNumberUtils
extends java.lang.Object
String
s 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
String s into BigDecimal s. |
static java.math.BigInteger |
asBigInteger(java.lang.String jsonNumberString)
Helper method for converting JSON number
String s into BigInteger s. |
static java.lang.Double |
asDouble(java.lang.String jsonNumberString)
Helper method for converting JSON number
String s into Double s. |
static java.lang.Integer |
asInteger(java.lang.String jsonNumberString)
Helper method for converting JSON number
String s into Integer s. |
public static java.math.BigDecimal asBigDecimal(java.lang.String jsonNumberString)
String
s into BigDecimal
s.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)
String
s into BigInteger
s.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)
String
s into Double
s. Note that use of this
method is risky as java Double
s 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)
String
s into Integer
s. Note that use of this
method is risky as java Integer
s have limited precision (between Integer.MIN_VALUE
and
Integer.MAX_VALUE
) whereas JSON numbers have unlimited precision.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.