Unconditionally close the peeked JsonReader. (#810)

It doesn't have an effect now, but this is for the future when closing the peeked source also clears buffers.
This commit is contained in:
Eric Cochran
2019-02-17 17:00:29 -08:00
committed by GitHub
parent a83a9b79e4
commit be6f3eb2af

View File

@@ -235,7 +235,12 @@ public final class PolymorphicJsonAdapterFactory<T> implements JsonAdapter.Facto
@Override public Object fromJson(JsonReader reader) throws IOException {
JsonReader peeked = reader.peekJson();
peeked.setFailOnUnknown(false);
int labelIndex = labelIndex(peeked);
int labelIndex;
try {
labelIndex = labelIndex(peeked);
} finally {
peeked.close();
}
if (labelIndex == -1) {
reader.skipValue();
return defaultValue;
@@ -262,7 +267,6 @@ public final class PolymorphicJsonAdapterFactory<T> implements JsonAdapter.Facto
+ reader.nextString()
+ "'. Register a subtype for this label.");
}
reader.close();
return labelIndex;
}