FasterXML / FasterXML/jackson-modules-java8

`WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS`/`READ_DATE_TIMESTAMPS_AS_NANOSECONDS` only work on numeric timestamps

Abierto
#374 31 comentarios 1 reacción 0 asignados Ver en GitHub
date-time-config
Lenguaje dominante
Java
Estrellas
425
Forks
124
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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:
```java
@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));
}
}
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.