-
Notifications
You must be signed in to change notification settings - Fork 122
Problem in serializing negative Duration values #165
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
Comments
Will take a look, but in the meantime, what release are you seeing this in, and what flags do you have set. (If you have a test case, that would be great.) Taking a quick look, the However, we happened to just be discussing this the other day and I think the nanos flag
Line 82 in ff084de
|
I think we are using 2.10.2 (can't check at the moment). Only feature we have set is the "write datetimes as timestamps"- one. I however did run the serialization on debugger while investigating and both if-conditions on that snippet were evaluating to true, but I didn't really think about that further I might be able to provide test case tomorrow |
Would you please try setting the SerializationFeature |
I created some test cases at https://github.com/jpsyri/jackson-duration-serialization Disabling the |
When
SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS
is true,Duration
s with negative value get serialized wrong. For exampleDuration.ofMillis(-1)
gets serialized as "-1.999000000"Problem seems to be in
DurationSerializer
where following code is used for serializingHowever
Duration
internally stores duration in format where seconds part basically containsfloor(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()
andgetNano()
return values according to that internal representation, which leads to the problem.The text was updated successfully, but these errors were encountered: