Closed
Description
When SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS
is true, Duration
s with negative value get serialized wrong. For example Duration.ofMillis(-1)
gets serialized as "-1.999000000"
Problem seems to be in DurationSerializer
where following code is used for serializing
generator.writeNumber(DecimalUtils.toBigDecimal(
duration.getSeconds(), duration.getNano()
));
However Duration
internally stores duration in format where seconds part basically contains floor(duration)
and nanoseconds part contains offset from that value to the actual duration. So n case of duration of -1 millisecond, the seconds part value will be -1 and nanoseconds part will be 999000000. getSeconds()
and getNano()
return values according to that internal representation, which leads to the problem.
Metadata
Metadata
Assignees
Labels
No labels