Open valepakh opened 1 week ago
Which Jackson version(s) was this tested with?
Which Jackson version(s) was this tested with?
2.18.1
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 double
s (lossy, range), or as BigDecimal
s (unlimited precision, range, non-lossy; but slower to handle).
By default, double
s 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.
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: