Java Integer, Long, BigInteger or BigDecimal generation from NUMBER(X,Y) JSON Schema type based on X and Y
See original GitHub issueCurrently jsonschema2pojo
always generates Java BigDecimal
for NUMBER(X,Y)
type JSON Schema even if Y=0
.
We suggest following more fine-tuned generation of Java types for NUMBER(X,Y)
:
- For
NUMBER(X,0)
whereX <= 9
generate JavaInteger
- For
NUMBER(X,0)
whereX >= 10
and X <= 18 generate JavaLong
- For
NUMBER(X,0)
whereX >= 19
generate JavaBigInteger
- For
NUMBER(X,Y)
whereY != 0
generate JavaBigDecimal
PS: We have JSON schema from third party with lots of NUMBER(X,0)
definitions and we were not able to persuade them to use integer
. This results in lots of Java BigDecimal
in our code with redundant conversions there and back which makes us unhappy.
Many thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Validator thinks integers should be 32-bits? Need very large ...
The BigInteger check doesn't make sense though, the JSON-Java library will parse such long numbers as strings, therefore the NumberSchema# ...
Read more >Java Integer And Java BigInteger Class With Examples
This Tutorial Explains Java Integer, Java Long, Max Int, NextInt() Method with Examples. We will also look at Java BigInteger Class & its ......
Read more >BigInteger support in jsonschema2pojo - Google Groups
Hi Joe, I want to generate a property whose type should be java.math.BigInteger. I've tried setting "type":"BigInteger" and ...
Read more >Numeric Functions - Data Virtuality Platform Documentation
Function Definition Data Type Constraint
ABS(x) Absolute value of x See standard numeric operators above
ACOS(x) Arc cosine of x x in , return type...
Read more >Built In Functions - Apache Pig!
3.1.5 Types Tables int long float double bigdecimal biginteger chararray bytearray ... Computes the number of elements based on any Pig data type....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@marcelmatula The less magic we have in defining how these types should be generated the better. This idea of using int/long for number when
multipleOf
is a whole number is interesting but this really isn’t how you are supposed to represent whole numbers. Yes type ‘number’ allows for any number, but if you require that a number is an integer then you should use"type": "integer"
.I appreciate this would be useful for you. However I think more people would be annoyed by this as would be pleased by it, and I feel it’s an odd choice to change the type. I’m going to close this as it isn’t really something I’m interested to add into jsonschema2pojo.
“number” type in json schema by definition means it’s decimal (float, double and BigDecimal)
If you want integers (int or long in Java), “integer” type is for disposition.