wanglingsong / JsonSurfer

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

Expose location from parsing context #53

Closed devcsrj closed 5 years ago

devcsrj commented 5 years ago

I have a use case, where I need to capture the current offset (i.e., line number, column number) in the stream from the ParsingContext. In jackson speak, this is the com.fasterxml.jackson.core.JsonLocation. I could probably capture this manually, by providing a custom JsonFactory that captures the returned parser from the createParser method (I haven't tried) so that I can query the native method.

It would be nice if this is natively supported in the ParsingContext.

wanglingsong commented 5 years ago

I would suggest you inject the custom JsonFactory into JacksonParser. I don't think it is necessary to add such support into ParsingContext interface. JsonSurfer is designed to be decoupled so that the JsonPath processing part works consistently no matter which Json parser you choose. So it's not a good idea to add this in a common interface only for Jackson.

devcsrj commented 5 years ago

So it's not a good idea to add this in a common interface only for Jackson.

Oh, I didn't expect that the other libraries doesn't have a concept of locations, or at least the byte offset.

No worries!