I have a class that will get serialized into JSON with the following attribute:
@JsonProperty("validTo") @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME) private OffsetDateTime validTo;
I’m also using the default spring-boot ObjectMapper with Jackson. This works fine if the
validTo DateTime has non-zero mili/nanoseconds. However, if they are zero, the result will not include them at all.
OffsetDateTime.of(2000, 10, 10, 10, 10, 10, 1000000, ZoneOffset.UTC) would correctly translate to
OffsetDateTime.of(2000, 10, 10, 10, 10, 10, 0, ZoneOffset.UTC) would incorrectly translate to
Why is that?
The javadoc of the format used in the annotation describes it as
The most common ISO Date Time Format yyyy-MM-dd'T'HH:mm:ss.SSSXXX — for example, "2000-10-31T01:30:00.000-05:00"., which appears to include the zeros.