Allow deserialization of a Number represented as a String (#964)
This commit is contained in:
parent
791236ac79
commit
44cad04a63
@ -368,6 +368,7 @@ public final class TypeAdapters {
|
||||
in.nextNull();
|
||||
return null;
|
||||
case NUMBER:
|
||||
case STRING:
|
||||
return new LazilyParsedNumber(in.nextString());
|
||||
default:
|
||||
throw new JsonSyntaxException("Expecting number, got: " + jsonToken);
|
||||
|
@ -158,6 +158,11 @@ public class PrimitiveTest extends TestCase {
|
||||
assertEquals(1L, actual.longValue());
|
||||
}
|
||||
|
||||
public void testNumberAsStringDeserialization() {
|
||||
Number value = gson.fromJson("\"18\"", Number.class);
|
||||
assertEquals(18, value.intValue());
|
||||
}
|
||||
|
||||
public void testPrimitiveDoubleAutoboxedSerialization() {
|
||||
assertEquals("-122.08234335", gson.toJson(-122.08234335));
|
||||
assertEquals("122.08112002", gson.toJson(new Double(122.08112002)));
|
||||
|
Loading…
Reference in New Issue
Block a user