question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Java Integer, Long, BigInteger or BigDecimal generation from NUMBER(X,Y) JSON Schema type based on X and Y

See original GitHub issue

Currently 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) where X <= 9 generate Java Integer
  • For NUMBER(X,0) where X >= 10 and X <= 18 generate Java Long
  • For NUMBER(X,0) where X >= 19 generate Java BigInteger
  • For NUMBER(X,Y) where Y != 0 generate Java BigDecimal

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:closed
  • Created 2 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
joelittlejohncommented, Feb 11, 2022

@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.

1reaction
eirnymcommented, Feb 11, 2022

“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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found