Fix JsonReader.hasNext() returning true at end of document (#2061)
This commit is contained in:
parent
be0a1f4ff7
commit
710a76c8b8
@ -101,7 +101,7 @@ public final class JsonTreeReader extends JsonReader {
|
||||
|
||||
@Override public boolean hasNext() throws IOException {
|
||||
JsonToken token = peek();
|
||||
return token != JsonToken.END_OBJECT && token != JsonToken.END_ARRAY;
|
||||
return token != JsonToken.END_OBJECT && token != JsonToken.END_ARRAY && token != JsonToken.END_DOCUMENT;
|
||||
}
|
||||
|
||||
@Override public JsonToken peek() throws IOException {
|
||||
|
@ -413,7 +413,7 @@ public class JsonReader implements Closeable {
|
||||
if (p == PEEKED_NONE) {
|
||||
p = doPeek();
|
||||
}
|
||||
return p != PEEKED_END_OBJECT && p != PEEKED_END_ARRAY;
|
||||
return p != PEEKED_END_OBJECT && p != PEEKED_END_ARRAY && p != PEEKED_EOF;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,4 +47,11 @@ public class JsonTreeReaderTest extends TestCase {
|
||||
in.skipValue();
|
||||
assertEquals(JsonToken.END_DOCUMENT, in.peek());
|
||||
}
|
||||
|
||||
public void testHasNext_endOfDocument() throws IOException {
|
||||
JsonTreeReader reader = new JsonTreeReader(new JsonObject());
|
||||
reader.beginObject();
|
||||
reader.endObject();
|
||||
assertFalse(reader.hasNext());
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,13 @@ public final class JsonReaderTest extends TestCase {
|
||||
assertEquals(JsonToken.END_DOCUMENT, reader.peek());
|
||||
}
|
||||
|
||||
public void testHasNextEndOfDocument() throws IOException {
|
||||
JsonReader reader = new JsonReader(reader("{}"));
|
||||
reader.beginObject();
|
||||
reader.endObject();
|
||||
assertFalse(reader.hasNext());
|
||||
}
|
||||
|
||||
public void testSkipArray() throws IOException {
|
||||
JsonReader reader = new JsonReader(reader(
|
||||
"{\"a\": [\"one\", \"two\", \"three\"], \"b\": 123}"));
|
||||
|
Loading…
Reference in New Issue
Block a user