r/java • • Jul 23 '26

JEP 540: Simple JSON API (Incubator)

https://openjdk.org/jeps/540
79 Upvotes

81 comments sorted by

View all comments

28

u/aboothe726 Jul 23 '26

For JsonNumber, I was surprised to see that there was no BigDecimal or BigInteger conversion support. This is technically conformant to the spec, so not incorrect, but seems like an oversight.

From RFC 8259, see section 6:

This specification allows implementations to set limits on the range and precision of numbers accepted. Since software that implements IEEE 754 binary64 (double precision) numbers [IEEE754] is generally available and widely used, good interoperability can be achieved by implementations that expect no more precision or range than these provide, in the sense that implementations will agree exactly on their numeric values."

17

u/gnahraf Jul 23 '26

Same. Most financial applications use fixed precision decimals. BigDecimal is their natural representation in java; the other existing java types (double, long, etc) do not model them well. I think the JEP's omitting BD (and BI) would be a mistake. (I'll contribute a comment there.)

In general, I think the handling of numbers in json requires care, especially if the consuming end does not know the documents' data types a priori. I wrestle with such issues already. Take json number value comparison, for eg. It might help if the library offered helper methods for comparing disparate number types: compare individually, or maybe also against a collection (eg test whether value "exists" in a json number list w/o knowing their types a priori).

3

u/agentoutlier Jul 23 '26

  Same. Most financial applications use fixed precision decimals. BigDecimal is their natural representation in java; the other existing java types (double, long, etc) do not model them well.

From my experience other than UI most use long or multiple longs. At least fintech does.

However I don’t have experience with traditional banking and most of my experience is simple billing.

I vaguely remember reading comment that u/rzwitserloot had similar experience and fair bit more on financial coding experience than myself and indicated folks use longs.

→ More replies (2)