mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -04:00
update number handling to use new helper method for consistency.
This commit is contained in:
parent
11e6b1af7e
commit
68883b9ff8
@ -1161,8 +1161,7 @@ public class JSONObject {
|
|||||||
return new BigDecimal((BigInteger) val);
|
return new BigDecimal((BigInteger) val);
|
||||||
}
|
}
|
||||||
if (val instanceof Double || val instanceof Float){
|
if (val instanceof Double || val instanceof Float){
|
||||||
final double d = ((Number) val).doubleValue();
|
if (!numberIsFinite((Number)val)) {
|
||||||
if(Double.isNaN(d)) {
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
return new BigDecimal(((Number) val).doubleValue());
|
return new BigDecimal(((Number) val).doubleValue());
|
||||||
@ -1212,11 +1211,10 @@ public class JSONObject {
|
|||||||
return ((BigDecimal) val).toBigInteger();
|
return ((BigDecimal) val).toBigInteger();
|
||||||
}
|
}
|
||||||
if (val instanceof Double || val instanceof Float){
|
if (val instanceof Double || val instanceof Float){
|
||||||
final double d = ((Number) val).doubleValue();
|
if (!numberIsFinite((Number)val)) {
|
||||||
if(Double.isNaN(d)) {
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
return new BigDecimal(d).toBigInteger();
|
return new BigDecimal(((Number) val).doubleValue()).toBigInteger();
|
||||||
}
|
}
|
||||||
if (val instanceof Long || val instanceof Integer
|
if (val instanceof Long || val instanceof Integer
|
||||||
|| val instanceof Short || val instanceof Byte){
|
|| val instanceof Short || val instanceof Byte){
|
||||||
@ -2267,18 +2265,8 @@ public class JSONObject {
|
|||||||
* If o is a non-finite number.
|
* If o is a non-finite number.
|
||||||
*/
|
*/
|
||||||
public static void testValidity(Object o) throws JSONException {
|
public static void testValidity(Object o) throws JSONException {
|
||||||
if (o != null) {
|
if (o instanceof Number && !numberIsFinite((Number) o)) {
|
||||||
if (o instanceof Double) {
|
throw new JSONException("JSON does not allow non-finite numbers.");
|
||||||
if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
|
|
||||||
throw new JSONException(
|
|
||||||
"JSON does not allow non-finite numbers.");
|
|
||||||
}
|
|
||||||
} else if (o instanceof Float) {
|
|
||||||
if (((Float) o).isInfinite() || ((Float) o).isNaN()) {
|
|
||||||
throw new JSONException(
|
|
||||||
"JSON does not allow non-finite numbers.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user