-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Hello,
I'm encountering a Jackson-related issue beginning with swagger-jaxrs2-jakarta library version 2.2.28
(This Swagger version updated Jackson from 2.16.2 to 2.18.2)
With this version of Jackson, the above error is shown when serializing / deserializing any class that utilizes the Java 8 date types.
Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
The jackson jsr310 library is of course already included as a dependency for Swagger, so to get around this error I have to create an ObjectMapper, register the JavaTimeModule, and create a custom serializer / deserializer that is used on any such date/time fields. (I am not using Spring Boot)
This resolves that particular error, however the problem is that the rest of the project is using Johnzon (Jsonb) rather than Jackson, and introducing those custom serialize / deserialize annotations on a class results in any existing Jsonb annotations there being ignored. For example, the deserialization of property names with underscores rather than camel case is ignored:
@JsonbProperty(name = "snake_case")
I also tried registeing the JavaTimeModule with swagger directly on startup, but the error still appears.
io.swagger.v3.core.util.Json.mapper().registerModule(new JavaTimeModule());
So it seems I am stuck between these two json libraries battling in my project. I'm not looking to maintain annotations for two different json serializer libraries on all of my classes. Does anyone know how I can get around Jackson's insistance regarding these date/time types? As I see it currently my only options are
- Add jackson-specific properties for all fields in every class that has Java 8 date types
- Move to using openAPI Microprofile rather than Swagger since it does not rely on Jackson
Thanks for your time