-
Notifications
You must be signed in to change notification settings - Fork 117
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
Instant precision should be retained in ObjectMapper#readTree (add JsonNodeFeature
to force use of BigDecimal
for JsonNode
reads)
#307
Comments
Right, But this is neither available now nor absolutely needed for your use case. You should probably define and use an intermediate POJO for values and make property you need to be of type |
Since the defined objects contain However, it appears that we may be able to copy the unmodifiable |
Ok. Use of |
Just want to chime in and add that, as of 2.17, this is an issue someone I work with had to find the hard way :( Out of curiosity, has any testing been done to approximate how much of a performance impact USE_BIG_DECIMAL_FOR_FLOATS has? Since ObjectMapper seems to effectively default to having it on, I can't imagine the impact would be significant. I'm inclined to globally turn it on (within my company) and am mostly looking for an excuse to not do so. Not that it's worth much, but we made another test (basically identical to the above) to validate:
|
Oh, this is in wrong repo; @Logic-32 I am not sure why you think |
Sorry. Perhaps "default" was the wrong word. What I mean is:
So, what I mean is that With that said, I kinda understand why you moved this case to |
Unfortunately I don't see another solution, aside possibly adding separate The issue is that although in theory we could change handling of So the question is whether processing itself absolutely requires |
I'm not immediately opposed to this idea. In general, I'd be surprised if anyone expected
In our case, we absolutely do not need |
Yeah the idea of adding the new feature would specifically be to allow forcing |
I'm not sure if that'll leave some other corner cases around but am not immediately opposed to it :) Afterall, my arguments against JsonNode in general is that it is not an efficient approach to deserialization. May as well at least make it "accurate" ;) |
Be that as it may, the intent with possible addition would be to give more granular configurability -- I do not think there is a way to automatically prevent the problem as per my earlier explanation & backwards compatibility constraints. |
JsonNodeFeature
to force use of BigDecimal
for JsonNode
reads)
No real update, other than mention the possibility of adding a new Also, adding a (failing) test based on code here, PR for, would be something useful. |
Since no one else did it, I added test (in bit simplified form), in case someone has time to dig into this in future (but as noted, can't be fixed by this module alone). |
Describe the bug
ObjectMapper#readValue(String)
seems to preserve all nine digits of anInstant
's decimal, butObjectMapper#readTree(JsonParser)
does not.Version information
Jackson 2.12.1
To Reproduce
The second test fails with:
Additional context
The failure case is derived from a custom deserializer in our project.
Ideally, I'd like
readTree
to retain theInstant
's precision in the same way thatObjectMapper#readValue
does when it deserializes aMap
that containsInstant
s, though I'd be happy with advice on how to change my approach in my deserializer instead.I realize also that
USE_BIG_DECIMAL_FOR_FLOATS
addresses this issue, but I'd prefer to avoid that, since others import our module.The text was updated successfully, but these errors were encountered: