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.

Add `JsonNode.canConvertToExactIntegral()` to indicate whether floating-point/BigDecimal values could be converted to integers losslessly

See original GitHub issue

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

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Oct 20, 2020

As per title, my current thinking is that method to add will be named

canConvertToExactIntegral()

and will next check that version. But can still consider even better naming until 2.12.0-rc2.

1reaction
cowtowncodercommented, Oct 16, 2020

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

Read more comments on GitHub >

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

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