-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jackson ZonedDateTime support #38
Comments
Apparently, the "old" JSR310Module is deprecated. [1] A way to deal with this can be: ObjectMapper mapper = JsonMapper.builder()
.findAndAddModules()
.build(); instead of ObjectMapper mapper = new ObjectMapper(); |
Even with this potential change, java time types are flexible and create some additional errors.
i.e. ZonedDateTime is very strict where may or may not include the time info. |
Defaulting some fields can be done by (from [1] DateTimeFormatter fmt = new DateTimeFormatterBuilder()
.appendValue(ChronoField.YEAR)
.parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
.parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
.parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
.toFormatter()
.withZone(ZoneOffset.UTC); Giving datetimeformatter to the objectmapper by (from [2] JavaTimeModule javaTimeModule = new JavaTimeModule();
LocalDateTimeDeserializer dateTimeDeserializer = new LocalDateTimeDeserializer(formatter);
LocalDateTimeSerializer dateTimeSerializer = new LocalDateTimeSerializer(formatter);
javaTimeModule.addDeserializer(LocalDateTime.class, dateTimeDeserializer);
javaTimeModule.addSerializer(LocalDateTime.class, dateTimeSerializer);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(javaTimeModule); I really don't like cluterring the code with these to be honest but I guess we might not have much option. And these examples are for for LocalDateTime and might not work on ZonedDateTime. |
Probably we will need a custom deser [1]. |
Fixed with #45 |
Some tests are failing due to:
Probably can be resolved by adding:
to pom.
The text was updated successfully, but these errors were encountered: