diff options
author | Leonid Startsev <sandwwraith@users.noreply.github.com> | 2023-04-19 18:15:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 18:15:55 +0200 |
commit | 350443a710e0ff0a50b9fcae8525522b86082b12 (patch) | |
tree | 52d680d5b08257dd5fefe0ee995ccb05ec906733 /formats/json-tests | |
parent | bbf248e2a006aa66398711654ca8d69a4c02821b (diff) | |
download | kotlinx.serialization-350443a710e0ff0a50b9fcae8525522b86082b12.tar.gz |
Fix incorrect json decoding iterator's .hasNext() behavior on array-wrapped inputs: (#2268)
hasNext() shouldn't throw exception if it was called more than once
after the stream has ended.
Fixes #2267
Diffstat (limited to 'formats/json-tests')
-rw-r--r-- | formats/json-tests/jvmTest/src/kotlinx/serialization/features/JsonLazySequenceTest.kt | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/formats/json-tests/jvmTest/src/kotlinx/serialization/features/JsonLazySequenceTest.kt b/formats/json-tests/jvmTest/src/kotlinx/serialization/features/JsonLazySequenceTest.kt index f6d13f70..23887660 100644 --- a/formats/json-tests/jvmTest/src/kotlinx/serialization/features/JsonLazySequenceTest.kt +++ b/formats/json-tests/jvmTest/src/kotlinx/serialization/features/JsonLazySequenceTest.kt @@ -83,6 +83,7 @@ class JsonLazySequenceTest { iter.assertNext(StringData("b")) iter.assertNext(StringData("c")) assertFalse(iter.hasNext()) + assertFalse(iter.hasNext()) // Subsequent calls to .hasNext() should not throw EOF or anything assertFailsWithMessage<SerializationException>("EOF") { iter.next() } @@ -186,4 +187,11 @@ class JsonLazySequenceTest { assertEquals(inputList, json.decodeToSequence(paddedWs.asInputStream(), StringData.serializer(), DecodeSequenceMode.ARRAY_WRAPPED).toList()) } + @Test + fun testToIteratorAndBack() = withInputs { ins -> + val iterator = Json.decodeToSequence(ins, StringData.serializer()).iterator() + val values = iterator.asSequence().take(3).toList() + assertEquals(inputList, values) + assertFalse(iterator.hasNext()) + } } |