Skip to content

Commit

Permalink
Merge pull request #592 from Alanscut/gson_provider
Browse files Browse the repository at this point in the history
improve number type
  • Loading branch information
kallestenflo committed May 18, 2020
2 parents 157dc08 + 6ff06c2 commit 1ed1ea0
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public Object unwrap(final Object o) {

private static boolean isPrimitiveNumber(final Number n) {
return n instanceof Integer ||
n instanceof Float ||
n instanceof Double ||
n instanceof Long ||
n instanceof BigDecimal ||
Expand All @@ -97,9 +98,9 @@ private static Number unwrapNumber(final Number n) {
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;
Expand Down

0 comments on commit 1ed1ea0

Please sign in to comment.