FasterXML / FasterXML/jackson-modules-java8

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

Đang mở
#374 31 bình luận 1 reaction 0 người được giao Xem trên GitHub
date-time-config
Ngôn ngữ chính
Java
Star
425
Fork
124
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.