提交 6ff06c21 编写于 作者: A Alanscut

improve number type

上级 588d61e9
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册