-
Notifications
You must be signed in to change notification settings - Fork 122
Open
Labels
date-time-configWork related to possible larger DateTimeConfig featureWork related to possible larger DateTimeConfig feature
Description
Hello.
I'm using Spring Boot 3.5.6 with Java 25 and I need a way to have Jackson to serialize/deserialize date-time values up to milliseconds precision and not higher (nanoseconds, actually).
I tried setting write-date-timestamps-as-nanoseconds and read-date-timestamps-as-nanoseconds to false, but it looks like they're simply ignored if I don't have write-dates-as-timestamps to true.
Indeed, I would like to have my JSON contain a date-time in the ISO standard format and not as a long value, but I wasn't able to find anything in the documentation for this.
I wonder why such a feature is provided only for numeric timestamps. It should work for both IMHO.
Below a small test case to reproduce the issue:
@SpringBootTest(
webEnvironment = MOCK,
properties = {
//"spring.jackson.serialization.write-dates-as-timestamps=true",
"spring.jackson.serialization.write-date-timestamps-as-nanoseconds=false",
"spring.jackson.deserialization.read-date-timestamps-as-nanoseconds=false"
}
)
public class ObjectMapperTest {
@Autowired
private ObjectMapper objectMapper;
@Test
public void shouldHandleDateTimeUpToMillis() throws JsonProcessingException {
// given
Instant instant = Instant.now().with(NANO_OF_SECOND, 1);
assertThat(instant.getNano()).isNotZero();
// when
String serialized = objectMapper.writeValueAsString(instant);
// then
Instant deserialized = objectMapper.readValue(serialized, Instant.class);
assertThat(deserialized).isEqualTo(instant.truncatedTo(MILLIS));
}
}Metadata
Metadata
Assignees
Labels
date-time-configWork related to possible larger DateTimeConfig featureWork related to possible larger DateTimeConfig feature