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();
|
in.nextNull();
|
||||||
return null;
|
return null;
|
||||||
case NUMBER:
|
case NUMBER:
|
||||||
|
case STRING:
|
||||||
return new LazilyParsedNumber(in.nextString());
|
return new LazilyParsedNumber(in.nextString());
|
||||||
default:
|
default:
|
||||||
throw new JsonSyntaxException("Expecting number, got: " + jsonToken);
|
throw new JsonSyntaxException("Expecting number, got: " + jsonToken);
|
||||||
|
@ -158,6 +158,11 @@ public class PrimitiveTest extends TestCase {
|
|||||||
assertEquals(1L, actual.longValue());
|
assertEquals(1L, actual.longValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNumberAsStringDeserialization() {
|
||||||
|
Number value = gson.fromJson("\"18\"", Number.class);
|
||||||
|
assertEquals(18, value.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
public void testPrimitiveDoubleAutoboxedSerialization() {
|
public void testPrimitiveDoubleAutoboxedSerialization() {
|
||||||
assertEquals("-122.08234335", gson.toJson(-122.08234335));
|
assertEquals("-122.08234335", gson.toJson(-122.08234335));
|
||||||
assertEquals("122.08112002", gson.toJson(new Double(122.08112002)));
|
assertEquals("122.08112002", gson.toJson(new Double(122.08112002)));
|
||||||
|
Loading…
Reference in New Issue
Block a user