New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal to expose Position information used for error messages in JSonReader in public API #2373
Comments
How reliable are these values though? It has been a while since I had a look at that but there might be cases where |
So far so good. How about I test them for a few weeks and see what comes up?
|
You don't have to test this only for this; I was just curious if you are already aware of any issues. My main concern is that by exposing this information with a public API But maybe these concerns are unjustified and supporting this in a reliable way would not be that difficult. Note that I am not a direct member of this project; they might think differently about this. |
That makes perfect sense. Your concern is with correctness and what the definition of it is. Let's have a go at defining what a "correct" implementation of
WDYT? did I get this right? |
This one follows from post-conditions such as |
Note sure for For array and objects I think it should be For Another point might be lenient-mode of |
Maybe it would be easier if you looked for a JSON parser which is explicitly designed to report accurate position information, possibly one which is used by IDEs such as in IntelliJ IDEA; haven't checked though which library they are using. Or alternatively a parser generator library such as ANTLR could be used, they already have an existing grammar for JSON: https://github.com/antlr/grammars-v4/blob/master/json/JSON.g4 (but the licensing might be a bit unclear, see antlr/grammars-v4#1607) |
I agree with the points made by @Marcono1234. If we exposed this information, there might be some impact on performance of certain cases (because the position we record now doesn't quite make sense). We would also be tying our hands for future parser changes, since we'd need to be sure to preserve the reported positions. I think the current situation, where you can get this information but only through reflection, is probably better. That makes it clear that you're going through a back door and that the reported positions might change in future versions of Gson. We probably wouldn't change them gratuitously: if you want, you can contribute a test that would fail if they did change. We still wouldn't guarantee anything, but at least we would know if one of our changes was going to alter the reported positions. Fundamentally I think there's a conflict between a fast parser, which Gson aims to be, and a detailed one. It might indeed be better to look at another JSON library. |
Thanks for maintaining this library!
Problem solved by the feature
Feature description
Proposal to expose the following fields of JsonReader:
With these public methods:
Using these methods just before
beginObject()
and just afterendObject()
you get an accurate measurementof the span of every object in the character stream.
Alternatives / workarounds
The text was updated successfully, but these errors were encountered: