Added test to use BigDecimal to parse number when requesting it as a long.

This commit is contained in:
Joel Leitch 2013-05-13 20:37:33 +00:00
parent f29d5bc37b
commit e4508227c5
2 changed files with 6 additions and 2 deletions

View File

@ -39,7 +39,7 @@ public final class LazilyParsedNumber extends Number {
try {
return (int) Long.parseLong(value);
} catch (NumberFormatException nfe) {
return new BigInteger(value).intValue();
return new BigDecimal(value).intValue();
}
}
}
@ -49,7 +49,7 @@ public final class LazilyParsedNumber extends Number {
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
return new BigInteger(value).longValue();
return new BigDecimal(value).longValue();
}
}

View File

@ -152,6 +152,10 @@ public class PrimitiveTest extends TestCase {
expected = new Long(json);
actual = gson.fromJson(json, Number.class);
assertEquals(expected.longValue(), actual.longValue());
json = "1.0";
actual = gson.fromJson(json, Number.class);
assertEquals(1L, actual.longValue());
}
public void testPrimitiveDoubleAutoboxedSerialization() {