Closed fbacchella closed 9 months ago
From stack trace, it looks like Duration
serializer was attempting to serialize value as nanoseconds, and that conversion fails due to overflow.
And looking at SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS
that is enabled by default...
I don't remember quite why this default was selected.
But maybe this could be fixed somehow; the smallest value is kind of special since it's the value for which there is no positive counterpart.
Ok, the way to enforce serialization as Seconds is like so:
// [datetime#282]
static class Bean282 {
@JsonFormat(pattern = "SECONDS")
public Duration duration;
public Bean282(Duration d) { duration = d; }
}
that is, @JsonFormat
is to be used. It is also possible to default this via:
mapper.configOverride(Duration.class)
.setFormat(JsonFormat.Value.forPattern("SECONDS"));
I will try to add bit more testing on this, but this is the way to configure things. Use of features will not be sufficient.
Pattern feature was added via #184.
Java’s JFR can generate evens that return value with a second port of value -9223372036854775808 (equals to Long.MIN_VALUE). Jackson failes to serialize that value:
throws:
If
WRITE_DURATIONS_AS_TIMESTAMPS
is set to false, it generate"PT-2562047788015215H-30M-8S"
Jackson version is 2.15.3.