Skip to content

Instantly share code, notes, and snippets.

@tomwhoiscontrary
Created September 1, 2021 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomwhoiscontrary/e0a32698c5f4083bf339a5a7eb4d9d01 to your computer and use it in GitHub Desktop.
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
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