-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Description
Say I have a class:
final class MyType {}
and a TypeAdapter
:
final class MyTypeAdapter extends TypeAdapter<MyType> {
// ...
@Override public MyType read(JsonReader in) throws IOException {
in.beginObject();
return new MyType();
}
}
Note the missing in.endObject()
call.
My calling code:
String json = "{}";
Gson gson = new GsonBuilder().registerTypeAdapter(MyType.class, new MyTypeAdapter()).create();
StringReader stringReader = new StringReader(json);
MyType myType = gson.fromJson(stringReader, MyType.class);
The above will correctly fail (JsonIOException: JSON document was not fully consumed.
).
However, using a JsonReader
instead (gson.fromJson(new JsonReader(stringReader), MyType.class)
) will not fail.
Is this working as intended?
Metadata
Metadata
Assignees
Labels
No labels