You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deserializing Instant from the string of "millis.nanos", which is the default serialization method in Jacskon yields different result when doing so through the ObjectMapper.readValue method or first reading it into a JsonNode through ObjectMapper.readTree and then reading the value from the tree via ObjectMapper.treeToValue
The root cause seems to be that readTree stores the information in the node in the double format, which then gets truncated when deserializing it to the Instant, while when deserializing directly, this step is skipped.
I wrote the test, which doesn't really uses a JSON but if you create a proper class with annotations and the field of type Instant the result will be the same:
Yes, I think this is an unfortunate side-effect of readTree() having to decide what to do with fractional numbers: whether to read them as 64-bit doubles (lossy, range), or as BigDecimals (unlimited precision, range, non-lossy; but slower to handle).
By default, doubles are used: this can be changed with config setting(s) but cannot be solved by Date/Time module itself.
Setting to enable is DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS and should retain accuracy.
cowtowncoder
changed the title
Different result of Instant deserialization between readValue and readTree/treeToValue
Different result of Instant deserialization between readValue and readTree/treeToValue
Nov 19, 2024
Deserializing
Instant
from the string of "millis.nanos", which is the default serialization method in Jacskon yields different result when doing so through theObjectMapper.readValue
method or first reading it into aJsonNode
throughObjectMapper.readTree
and then reading the value from the tree viaObjectMapper.treeToValue
The root cause seems to be that
readTree
stores the information in the node in thedouble
format, which then gets truncated when deserializing it to theInstant
, while when deserializing directly, this step is skipped.I wrote the test, which doesn't really uses a JSON but if you create a proper class with annotations and the field of type
Instant
the result will be the same:The text was updated successfully, but these errors were encountered: