-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
JsonReader API call to determine whether Number was specified as whole number (no period) or floating-point (period) #2217
Comments
Possibly a duplicate of #1621 Are you really working directly with If you are working directly with a It would be good if you could explain your use case a bit more in detail or provide the code you have so far. |
I'm attempting to make best possible sense out of a wide variety of JSON files whose provenance is not entirely clear, and there is no documentation. First thing I need is to faithfully "read it in" so then I can throw some smarts at it to figure out what it might possibly mean. If the first step is already losing information, the second steps become harder. I read through the code and I'm now attempting to read as Long, and if that throws, I retry as Double. That gives me a workaround. |
Your workaround might not work as desired when the number has 0 as decimal place, such as the 17.0 in your example. gson/gson/src/main/java/com/google/gson/stream/JsonReader.java Lines 976 to 980 in e614e71
I think checking first for |
Gotcha. You are right :-) |
Do you think this issue can be closed? I think for inspecting the exact number format the approach of checking One issue with a I am not sure what other situations exist where it is really necessary to peek the number type. In all cases the |
Whatever I can suggest now would break the existing API, and so I won't. Ok, closing. |
I'd like to be able to tell the difference between
{ "x" : 17 }
and
{ "x" : 17.0 }
You internally distinguish between those two, but there is no API that exposes this. It might be as simple as adding a call:
boolean peekIsWholeNumber()
The text was updated successfully, but these errors were encountered: