Skip to content

Handle precise and large numbers - #128

Closed
FritzMock wants to merge 1 commit into
stleary:masterfrom
FritzMock:master
Closed

FritzMock wants to merge 1 commit into
stleary:masterfrom
FritzMock:master

Conversation

@FritzMock

Copy link
Copy Markdown

Use BigDecimal and BigInteger for numbers that will either be to precise for Double or to large for Long.
Since the conversion of Numbers changed, also some invalid notations of JSON-numbers that got parsed before will no longer be supported. @see differences between Double.valueOf(String s) and new BigDecimal(String s)

@stleary

stleary commented May 23, 2015

Copy link
Copy Markdown
Owner

This looks like an enhancement, not a bug fix. No changes to the API, but see below. The internal behavior has changed. Some data inputs may no longer be allowed, which will probably be unacceptable and should be avoided, invalid or not.

The RFC does not seem to define numbers sharply, and allows implementations to restrict the range of numbers processed. Interoperability is mentioned as a concern, since users may assume that all implementations support the same ranges as what they use locally. JSON-Java advertises its numeric restrictions in the API contract: only double, long, int, and in places Number is supported.

It would probably be advisable to add new API methods for BigDecimal and BigInteger in JSONObject, JSONArray, JSONWriter, etc. Other internal areas of the code may have to be touched as well.

It seems reasonable to enhance JSON-Java to take a larger numeric range. Merging should not be performed until all code changes are completed and concerns addressed. Will this work for you?

@FritzMock

Copy link
Copy Markdown
Author

A new API for BigDecimal/BigInteger will be impossible without changing parsing and internal representation of numbers and that will ultimately change behaviour.
To preserve current behaviour we would end up in two different "modes of operation", switching code/types at various places. Or we duplicate lots of code in parallel classes. Neither is an approach I generally do not like much, introduces unneeded complexity and causes more work than actually needed with a clean design (i.e. BigDecimal/BigInteger as only internal representation.)
But since JSON-java lacks efficient versioning, there is no choice but seamless integration or a complete fork ...
I will give it some try, with adding new API methods and switching modes of operation.

@stleary

stleary commented Jun 18, 2015

Copy link
Copy Markdown
Owner

We should shift discussion of support for BigDecimal and BigInteger to #126. If I missed something important to this issue, please bring it up there. I don't think other changes to the numeric behavior of JSON-Java will be able to get traction, given the need to maintain backwards compatibility. Thanks for bringing up the issue, hopefully it will lead to improved big number support.

@stleary stleary closed this Jun 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants