I'm reading JEP 198 and sketching out what an implementation could look
like pursuant to this old conversation.

https://mail.openjdk.org/pipermail/discuss/2020-April/005401.html

My biggest question right now is what does the JEP mean exactly by
"document context"


   - Parsing APIs which allow a choice of parsing token stream, event
   (includes document hierarchy context) stream, or immutable tree
   representation views of JSON documents and data streams.



So token stream I understand as something akin to

sealed interface Token {
    record StartArray() implements Token {}
    record EndArray() implements Token {}
    record StartObject() implements Token {}
    record EndObject() implements Token {}
    record Number(Json.Number value) implements Token {}
    record String(Json.String value) implements Token {}
    record True() implements Token {}
    record False() implements Token {}
    record Null() implements Token {}
}

Which matches up with the model in
https://fasterxml.github.io/jackson-core/javadoc/2.7/com/fasterxml/jackson/core/JsonToken.html

And an immutable tree representation as akin to

sealed interface Json {
    sealed interface Array extends Json, List<Json> ...
    sealed interface Object extends Json, Map<java.lang.String, Json> ...
    sealed abstract class Number extends java.lang.Number implements Json
...
    sealed interface String extends Json, CharSequence ...
    sealed interface Boolean ...
    sealed interface Null extends Json ...
}

Which, ignoring the open questions of
* Does the immutable tree need to be eagerly realized?
* Do we need to wait for valhalla to land
* Do we need to wait for full pattern matching to land

(because they make me sad)

I'm still unsure what information needs to be included in an "Event" stream
that would constitute "document context". Is it pointers to parent
collections? The current "Path"?

sealed interface PathElement {
    record Field(String fieldName) implements PathElement {}
    record Index(int index) implements PathElement {}
}

Reply via email to