Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gson.assertFullConsumption should throw JsonSyntaxException if JSON was not fully consumed #1720

Closed
Marcono1234 opened this issue Jun 10, 2020 · 0 comments · Fixed by #2122
Closed

Comments

@Marcono1234
Copy link
Collaborator

Currently Gson.assertFullConsumption throws a JsonIOException if the JSON was not fully consumed:

private static void assertFullConsumption(Object obj, JsonReader reader) {
try {
if (obj != null && reader.peek() != JsonToken.END_DOCUMENT) {
throw new JsonIOException("JSON document was not fully consumed.");
}

Maybe it would be better to throw a JsonSyntaxException instead, because:

  • The problem is not really IO related because reading worked without issues (no IOException was thrown)
  • This code is also called by fromJson(String, ...) which does not declare that it can throw a JsonIOException

For the case where a type adapter is not properly consuming all input (see also #835) neither would match perfectly though that might be acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant