Added test to use BigDecimal to parse number when requesting it as a long.
This commit is contained in:
parent
f29d5bc37b
commit
e4508227c5
@ -39,7 +39,7 @@ public final class LazilyParsedNumber extends Number {
|
|||||||
try {
|
try {
|
||||||
return (int) Long.parseLong(value);
|
return (int) Long.parseLong(value);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
return new BigInteger(value).intValue();
|
return new BigDecimal(value).intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ public final class LazilyParsedNumber extends Number {
|
|||||||
try {
|
try {
|
||||||
return Long.parseLong(value);
|
return Long.parseLong(value);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return new BigInteger(value).longValue();
|
return new BigDecimal(value).longValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +152,10 @@ public class PrimitiveTest extends TestCase {
|
|||||||
expected = new Long(json);
|
expected = new Long(json);
|
||||||
actual = gson.fromJson(json, Number.class);
|
actual = gson.fromJson(json, Number.class);
|
||||||
assertEquals(expected.longValue(), actual.longValue());
|
assertEquals(expected.longValue(), actual.longValue());
|
||||||
|
|
||||||
|
json = "1.0";
|
||||||
|
actual = gson.fromJson(json, Number.class);
|
||||||
|
assertEquals(1L, actual.longValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPrimitiveDoubleAutoboxedSerialization() {
|
public void testPrimitiveDoubleAutoboxedSerialization() {
|
||||||
|
Loading…
Reference in New Issue
Block a user