Browse Source

Merge pull request #592 from Alanscut/gson_provider

improve number type
pull/624/head
kallestenflo 5 years ago committed by GitHub
parent
commit
1ed1ea08a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      json-path/src/main/java/com/jayway/jsonpath/spi/json/GsonJsonProvider.java

5
json-path/src/main/java/com/jayway/jsonpath/spi/json/GsonJsonProvider.java

@ -85,6 +85,7 @@ public class GsonJsonProvider extends AbstractJsonProvider {
private static boolean isPrimitiveNumber(final Number n) {
return n instanceof Integer ||
n instanceof Float ||
n instanceof Double ||
n instanceof Long ||
n instanceof BigDecimal ||
@ -97,9 +98,9 @@ public class GsonJsonProvider extends AbstractJsonProvider {
if (!isPrimitiveNumber(n)) {
BigDecimal bigDecimal = new BigDecimal(n.toString());
if (bigDecimal.scale() <= 0) {
if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
if (bigDecimal.abs().compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
unwrapped = bigDecimal.intValue();
} else if (bigDecimal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0){
} else if (bigDecimal.abs().compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0){
unwrapped = bigDecimal.longValue();
} else {
unwrapped = bigDecimal;

Loading…
Cancel
Save