Skip to content
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

Bug in JSONParser: always parse numbers as double even if long is expected #1254

Closed
codenameone opened this issue Mar 27, 2015 · 1 comment
Closed

Comments

@codenameone
Copy link
Collaborator

Original issue 1255 created by codenameone on 2015-01-04T19:55:30.000Z:

You can reproduce issue using simulator by just parsing some JSON with integer values.

There is special flag useLongsDefault in JSONParser class that can be set via static methods. As I see from the code if this flag is set then all numbers without a dot should be parsed into Long variable. Instead they are parsed into double. After some investigations I figured out that this was caused by the bug in the code (at least I think so).

There are such snippet in few places in method parse(..):

if(useLongsDefault) {
if(ct.indexOf('.') > -1) {
callback.numericToken(Double.parseDouble(ct));
} else {
callback.numericToken(Long.parseLong(ct));
}
} else {
callback.numericToken(Double.parseDouble(ct));
}

The problem is that method callback.numericToken(..) always treat token as a double value. So I think that for case when long is expected another callback method should be used -> callback.longToken(..).

@codenameone
Copy link
Collaborator Author

Comment #1 originally posted by codenameone on 2015-01-08T09:36:08.000Z:

Thanks, fixed in SVN.

@codenameone codenameone removed their assignment Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0 participants