Closed sven-v-t-veer closed 3 years ago
Your problem is that you do not register Java 8 date/time module with ObjectMapper
you are using: you need to do one of:
// newer, 2.10+
ObjectMapper mapper = JsonMapper.builder()
.addModule(new JavaTimeModule())
.build();
// or older pre-2.10 (works still with 2.10+)
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
2.12 will actually prevent reading/writing of java.time.
values without explicitly registered handlers because previously (as you saw) serialization would assume these are simple POJO values that then can not be read back at all.
Thanks!
I'm just upgrading some legacy code, upgrading from Jackson version 2.8.2.
It's clear to me now that it has always been used wrong.
@sven-v-t-veer Ah. Yes, these cases can be tricky. I hope you can get the issue resolved.
I'm using the jackson-datatype-jsr310 module in my (spring) application. The issue occurs with any version over 2.11.4. I have simplified the issue: POJO:
Application:
Relevant section of build.gradle:
Stacktrace:
By changing the version to 2.11.4, the output is:
output: {"aDateTime":{"offset":{"totalSeconds":0,"id":"Z","rules":{"transitions":[],"transitionRules":[],"fixedOffset":true}},"nano":641484000,"year":2021,"monthValue":6,"dayOfMonth":1,"hour":8,"minute":30,"second":32,"dayOfWeek":"TUESDAY","dayOfYear":152,"month":"JUNE"}}