Skip to content

Commit 1ed1ea0

Browse files
authored
Merge pull request #592 from Alanscut/gson_provider
improve number type
2 parents 157dc08 + 6ff06c2 commit 1ed1ea0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public Object unwrap(final Object o) {
8585

8686
private static boolean isPrimitiveNumber(final Number n) {
8787
return n instanceof Integer ||
88+
n instanceof Float ||
8889
n instanceof Double ||
8990
n instanceof Long ||
9091
n instanceof BigDecimal ||
@@ -97,9 +98,9 @@ private static Number unwrapNumber(final Number n) {
9798
if (!isPrimitiveNumber(n)) {
9899
BigDecimal bigDecimal = new BigDecimal(n.toString());
99100
if (bigDecimal.scale() <= 0) {
100-
if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
101+
if (bigDecimal.abs().compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
101102
unwrapped = bigDecimal.intValue();
102-
} else if (bigDecimal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0){
103+
} else if (bigDecimal.abs().compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0){
103104
unwrapped = bigDecimal.longValue();
104105
} else {
105106
unwrapped = bigDecimal;

0 commit comments

Comments
 (0)