|
|
@ -14,28 +14,25 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.jayway.jsonpath.spi.json; |
|
|
|
package com.jayway.jsonpath.spi.json; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.google.gson.JsonArray; |
|
|
|
import com.google.gson.JsonArray; |
|
|
|
import com.google.gson.JsonElement; |
|
|
|
import com.google.gson.JsonElement; |
|
|
|
import com.google.gson.JsonObject; |
|
|
|
import com.google.gson.JsonObject; |
|
|
|
import com.google.gson.JsonParser; |
|
|
|
import com.google.gson.JsonParser; |
|
|
|
import com.google.gson.JsonPrimitive; |
|
|
|
import com.google.gson.JsonPrimitive; |
|
|
|
import com.google.gson.internal.LazilyParsedNumber; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.jayway.jsonpath.InvalidJsonException; |
|
|
|
import com.jayway.jsonpath.InvalidJsonException; |
|
|
|
import com.jayway.jsonpath.JsonPathException; |
|
|
|
import com.jayway.jsonpath.JsonPathException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
|
|
import java.math.BigInteger; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
public class GsonJsonProvider extends AbstractJsonProvider { |
|
|
|
public class GsonJsonProvider extends AbstractJsonProvider { |
|
|
|
|
|
|
|
|
|
|
|
private static final JsonParser PARSER = new JsonParser(); |
|
|
|
private static final JsonParser PARSER = new JsonParser(); |
|
|
@ -86,25 +83,38 @@ public class GsonJsonProvider extends AbstractJsonProvider { |
|
|
|
return o; |
|
|
|
return o; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean isPrimitiveNumber(final Number n) { |
|
|
|
|
|
|
|
return n instanceof Integer || |
|
|
|
|
|
|
|
n instanceof Double || |
|
|
|
|
|
|
|
n instanceof Long || |
|
|
|
|
|
|
|
n instanceof BigDecimal || |
|
|
|
|
|
|
|
n instanceof BigInteger; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Number unwrapNumber(final Number n) { |
|
|
|
private static Number unwrapNumber(final Number n) { |
|
|
|
Number unwrapped; |
|
|
|
Number unwrapped; |
|
|
|
|
|
|
|
|
|
|
|
if (n instanceof LazilyParsedNumber) { |
|
|
|
if (!isPrimitiveNumber(n)) { |
|
|
|
LazilyParsedNumber lpn = (LazilyParsedNumber) n; |
|
|
|
BigDecimal bigDecimal = new BigDecimal(n.toString()); |
|
|
|
BigDecimal bigDecimal = new BigDecimal(lpn.toString()); |
|
|
|
|
|
|
|
if (bigDecimal.scale() <= 0) { |
|
|
|
if (bigDecimal.scale() <= 0) { |
|
|
|
if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) { |
|
|
|
if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) { |
|
|
|
unwrapped = bigDecimal.intValue(); |
|
|
|
unwrapped = bigDecimal.intValue(); |
|
|
|
} else { |
|
|
|
} else if (bigDecimal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0){ |
|
|
|
unwrapped = bigDecimal.longValue(); |
|
|
|
unwrapped = bigDecimal.longValue(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
unwrapped = bigDecimal; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
unwrapped = bigDecimal.doubleValue(); |
|
|
|
final double doubleValue = bigDecimal.doubleValue(); |
|
|
|
|
|
|
|
if (BigDecimal.valueOf(doubleValue).compareTo(bigDecimal) != 0) { |
|
|
|
|
|
|
|
unwrapped = bigDecimal; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
unwrapped = doubleValue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
unwrapped = n; |
|
|
|
unwrapped = n; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return unwrapped; |
|
|
|
return unwrapped; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|