Created
September 1, 2021 19:08
-
-
Save tomwhoiscontrary/e0a32698c5f4083bf339a5a7eb4d9d01 to your computer and use it in GitHub Desktop.
Parsing a sequence of JSON values that are not enclosed in a JSON array - https://github.com/leadpony/joy/issues/14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jakarta.json.Json; | |
import jakarta.json.JsonValue; | |
import jakarta.json.stream.JsonParser; | |
import org.junit.jupiter.api.Test; | |
import java.io.StringReader; | |
public class DoesWhatTheJavadocSaysTest { | |
@Test | |
void canBeUsedToParseSequenceOfJSONValuesThatAreNotEnclosedInAJSONArray() { | |
/* | |
JsonParser can be used to parse sequence of JSON values that are not enclosed in a JSON array, e.g. { } { }. The following code demonstrates how to parse such sequence. | |
JsonParser parser = Json.createParser(...); | |
while (parser.hasNext) { | |
parser.next(); // advance parser state | |
JsonValue value = parser.getValue(); | |
} | |
https://eclipse-ee4j.github.io/jsonp/docs/api/jakarta.json/jakarta/json/stream/JsonParser.html | |
*/ | |
JsonParser parser = Json.createParser(new StringReader("{ } { }")); | |
while (parser.hasNext()) { | |
parser.next(); // advance parser state | |
JsonValue value = parser.getValue(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment