jsonp-api
jsonp-api copied to clipboard
Enable to pass a list of jsonpointers like to whitelist/blacklist in jsonparser
When you know what you read, passing some whitelist/blacklist of parser events to skip can enable to reduce memory consumption and optimize the execution.
This is somehow related to https://github.com/eclipse-ee4j/jsonb-api/issues/224#issuecomment-590126204
Side note: can need to generalize jsonpointer syntax to support wildcards for arrays.
This is an intriguing idea. The set of pointers could determine whether or not the parser automatically skips over events. Might be tricky to specify this in a non-ambiguous way, though, in the face of contradictory whitelist/blacklists.
Parsers should already be able to skip allocating memory for events that are not consumed by the caller. I see no advantage to pushing query processing or redaction inside the parser.
Spec defines JsonPointer, if a set can be passed to the parser then it sounds easy to impl and configure. Today there is only next() and next enable getXXX access so there is no way to skip anything.
No, there is also skipObject() and skipArray(). And there is no requirement that next() has to materialize anything. Materialization can be postponed until getXXX is actually called.
I don't think memory consumption is the real concern here. Skipping is implied when getXXX is not called. Perhaps the documentation should be clearer in this regard, but it's an implementation detail. From an API perspective, it is clear.
That being said, I could definitely see JsonParser#skipTo(JsonPointer) being useful since JSON-P seems to be embracing RFC 6901. It wouldn't be much of a stretch to enable registering whitelist/blacklist pointers as part of the config when generating a JsonParserFactory, either.
There is a requirement to materialize next by design, you cant impl getString if you didnt stored it somewhere - mem, disk, ... - so requirement is built in.
For ex, you cant skip an event string value today, even if you know it does 10g (yes xml in json but it exists).
SkipTo is ok but id expect more a jsonParserFactory.createParser(...., new JsonPointer[]{....}) to be able to pass multiple ones
The ability to evaluate JsonPointer over JsonParser is reasonable but I don't think this should be added to the parser api. The parser api should remain independent of specific path evaluation languages. There is no reason this functionality can't be implemented outside of the parser. And the premise that next() requires string materialization is not correct.
@rmannibucau A parser can basically tell by the first character what the event is. No need to move any further until asked to. If getXXX() is never called, the parser can advance to the next token while discarding all the characters it examines.
@jjspiegel That makes sense. Something like JsonPointer#seek(JsonParser) would do the trick.
No, even not called value is materialized - at least in byte[], check out all impl out there. API requires it by its design so parser api cant read some document it should and jsonb cant support some mapping it could forking jsonp.