-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JsonNode.canConvertToExactIntegral()
to indicate whether floating-point/BigDecimal values could be converted to integers losslessly
#2885
Comments
Hmmh. No, I don't think that would be good idea, changing semantics in a minor version. However, there is |
Well, sort of, integral check can be accomplished by combining Thanks for the quick reply and feel free to ping me if you'd like a PR for the next major release. |
Ah, yes, checking for missing fractional part is sort of orthogonal, so those methods do not quite match what you are trying to do. So it might be request for yet-another accessor ( |
Yes that's the case and everyone who needs to check fraction will re-implement the same fractional check logic downstream. An accessor like |
@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). |
JsonNode.hasFractionalPart()
to indicate whether floating-point/BigDecimal values could be converted to integers losslessly
Hi |
@bmsbharathi sorry for the slow response: looks like @siavashsoleymani has unfortunately already contributed a PR. |
Ok, so, I think PR being worked on has functionality that will work on But now I wonder about naming of the method. Mostly since there's now the question of what to return in cases of:
so since the intent is usually not to check for existence of fraction as much as whether node is losslessly convertible to integral value, this might lead to awkward checks since I wonder should we not instead name method like:
or if we stick with check for fractions, switch it to instead use negation
because then we could return WDYT? |
#2885: Add JsonNode.hasFractionalPart() Co-authored-by: siavashsoleymani <[email protected]>
Initial PR merged; will now ponder renaming -- leaning towards changing to something more like
|
JsonNode.hasFractionalPart()
to indicate whether floating-point/BigDecimal values could be converted to integers losslesslyJsonNode.canConvertToExactIntegral()
to indicate whether floating-point/BigDecimal values could be converted to integers losslessly
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. |
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 parentJsonNode.isIntegralNumber
.Describe the solution you'd like
Implement
DecimalNode.isIntegralNumber
to return true if the value can fit into Long or IntUsage 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 propertyThe text was updated successfully, but these errors were encountered: