wanglingsong / JsonSurfer

A streaming JsonPath processor in Java
MIT License
292 stars 55 forks source link

Could CollectOneListner be made public now collectOne is deprecated? No simple replacement exists? #74

Closed NielsUll closed 2 years ago

NielsUll commented 2 years ago

I need to extract one element from the beginning of a large json structure, and would like to abort parsing as soon as it is found. The collectOne() looks like just the thing, but it is deprecated.

The CollectOneListener is not public, so I have to clone that class in my own code?

wanglingsong commented 2 years ago

you can try the new API. https://github.com/jsurfer/JsonSurfer#collect-value-by-jsonpath

NielsUll commented 2 years ago

But that will still parse the entire message? I tested this trying to read this:

{ "key1": "value1", "key2": "value2", something which is definitly not valid json

I can read value1 using collectOne(), but not using the new API - it will try to parse everything.

My issue is not with invalid json as above, but with parsing several megabytes of json when the value I need is within the first 100 bytes or so.

wanglingsong commented 2 years ago

If you want to stop immediately on the first occurrence. this example may help: https://github.com/jsurfer/JsonSurfer#stoppable-parsing

NielsUll commented 2 years ago

Thank you - I had apparently missed that.