mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
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:
@@ -235,7 +235,12 @@ public final class PolymorphicJsonAdapterFactory<T> implements JsonAdapter.Facto
|
|||||||
@Override public Object fromJson(JsonReader reader) throws IOException {
|
@Override public Object fromJson(JsonReader reader) throws IOException {
|
||||||
JsonReader peeked = reader.peekJson();
|
JsonReader peeked = reader.peekJson();
|
||||||
peeked.setFailOnUnknown(false);
|
peeked.setFailOnUnknown(false);
|
||||||
int labelIndex = labelIndex(peeked);
|
int labelIndex;
|
||||||
|
try {
|
||||||
|
labelIndex = labelIndex(peeked);
|
||||||
|
} finally {
|
||||||
|
peeked.close();
|
||||||
|
}
|
||||||
if (labelIndex == -1) {
|
if (labelIndex == -1) {
|
||||||
reader.skipValue();
|
reader.skipValue();
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@@ -262,7 +267,6 @@ public final class PolymorphicJsonAdapterFactory<T> implements JsonAdapter.Facto
|
|||||||
+ reader.nextString()
|
+ reader.nextString()
|
||||||
+ "'. Register a subtype for this label.");
|
+ "'. Register a subtype for this label.");
|
||||||
}
|
}
|
||||||
reader.close();
|
|
||||||
return labelIndex;
|
return labelIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user