ensuring that the type field is written by runtime type adapter
This commit is contained in:
parent
7d96ce8d6d
commit
fdaa6b05c4
|
@ -55,6 +55,7 @@ public final class RuntimeTypeAdapterFactoryFunctionalTest extends TestCase {
|
||||||
json = gson.toJson(shape);
|
json = gson.toJson(shape);
|
||||||
shape = gson.fromJson(json, Shape.class);
|
shape = gson.fromJson(json, Shape.class);
|
||||||
assertEquals(15, ((Square)shape).side);
|
assertEquals(15, ((Square)shape).side);
|
||||||
|
assertEquals(ShapeType.SQUARE, shape.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonAdapter(Shape.JsonAdapterFactory.class)
|
@JsonAdapter(Shape.JsonAdapterFactory.class)
|
||||||
|
@ -163,7 +164,7 @@ public final class RuntimeTypeAdapterFactoryFunctionalTest extends TestCase {
|
||||||
return new TypeAdapter<R>() {
|
return new TypeAdapter<R>() {
|
||||||
@Override public R read(JsonReader in) throws IOException {
|
@Override public R read(JsonReader in) throws IOException {
|
||||||
JsonElement jsonElement = Streams.parse(in);
|
JsonElement jsonElement = Streams.parse(in);
|
||||||
JsonElement labelJsonElement = jsonElement.getAsJsonObject().remove(typeFieldName);
|
JsonElement labelJsonElement = jsonElement.getAsJsonObject().get(typeFieldName);
|
||||||
if (labelJsonElement == null) {
|
if (labelJsonElement == null) {
|
||||||
throw new JsonParseException("cannot deserialize " + baseType
|
throw new JsonParseException("cannot deserialize " + baseType
|
||||||
+ " because it does not define a field named " + typeFieldName);
|
+ " because it does not define a field named " + typeFieldName);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user