Add `JsonNode.canConvertToExactIntegral()` to indicate whether floating-point/BigDecimal values could be converted to integers losslessly
See original GitHub issueIs your feature request related to a problem? Please describe.
DecimalNode might contain a valid integer or long, however DecimalNode.isIntegralNumber
doesn’t cover such cases and return false from parent JsonNode.isIntegralNumber
.
Describe the solution you’d like
Implement DecimalNode.isIntegralNumber
to return true if the value can fit into Long or Int
Usage example DecimalNode.isIntegralNumber(-1) == true
Additional context
I want to use this check during json schema validation so that e.g. a DecimalNode containing an integer smaller than maximum long value can be considered as integer during type validation where schema has integer
as type of the property
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
JsonNode (jackson-databind 2.13.0 API) - FasterXML
Method that can be used to check whether contained value is numeric (returns true for isNumber() ) and can be losslessly converted to...
Read more >SUSE alert SUSE-SU-2022:1678-1 (jackson-databind ...
canConvertToExactIntegral()' to indicate whether floating-point/BigDecimal values could be converted to integers losslessly + Improve static ...
Read more >How to convert JsonNode to ObjectNode - java - Stack Overflow
You can convert a JsonNode in an ObjectNode in this simple way: ObjectNode objectNode = jsonNode.deepCopy();.
Read more >Class JsonNode - Adobe Developer
Method that will try to convert value of this node to a Java int. ... value is numeric (returns true for isNumber() )...
Read more >Working with Tree Model Nodes in Jackson - Baeldung
This tutorial will focus on working with tree model nodes in Jackson. We'll use JsonNode for various conversions as well as adding, ...
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 FreeTop 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
Top GitHub Comments
As per title, my current thinking is that method to add will be named
and will next check that version. But can still consider even better naming until 2.12.0-rc2.
@oguzhanunlu Sure: I’ll change the title and mark this as potentially good first issue for someone to consider implementing; and it could go in a new minor version (2.12 if contribution came quickly enough; 2.13 otherwise).