r/java
•
u/loicmathieu
•
Jul 23 '26
•
1
JEP 540: Simple JSON API (Incubator)
https://openjdk.org/jeps/540
79
Upvotes
View all comments
Show parent comment
17
u/s888marks Jul 23 '26
We provided
asDoublebecause of the section of the RFC that you quoted. We providedasLongbecause people use JSON numbers for integral values, at least those that can be represented in 53 or fewer bits. Butintis used in a lot of Java programs, and we suspected that many people would downcast toint(introducing subtle errors) instead of usingMath.toIntExactand so we addedasIntas well.We considered direct conversion methods to BigInteger and BigDecimal, but these types are probably used much less frequently than the primitives. It's possible to convert to them via String, for example,
which is only a few characters longer in source code. It might be possible to optimize the JsonNumber-to-BigDecimal conversion path, but it's unclear whether it would provide enough benefit to justify adding a new API point.