I have SpringBoot Java (server stub) code generated from a YAML API definition file which I coded in SwaggerHub. I use Open API 3.
I cannot get this generated code working, seems quite buggy.
The error I cannot fix is this one:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.OffsetDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: io.swagger.v3.oas.models.OpenAPI["components"]->io.swagger.v3.oas.models.Components["schemas"]->java.util.TreeMap["CancelData"]->io.swagger.v3.oas.models.media.ObjectSchema["properties"]->java.util.TreeMap["dateStamp"]->io.swagger.v3.oas.models.media.DateTimeSchema["example"])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.13.1.jar!/:2.13.1]
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1300) ~[jackson-databind-2.13.1.jar!/:2.13.1]
at com.fasterxml.jackson.databind.ser.impl.UnsupportedTypeSerializer.serialize(UnsupportedTypeSerializer.java:35) ~[jackson-databind-2.13.1.jar!/:2.13.1]
I get it when I git the API docs URL.
localhost:8080/.../api-docs
I tried all suggestion which I could find on the web but nothing helps.
I think it's related to this field which I have in my YAML file.
dateStamp:
type: string
format: date-time
description: The creation date and time of this cancel transaction
example: "2022-01-28T05:03:57Z"
I tried registering JavaTimeModule and all that was suggested on the web. I don't understand this error. I don't know even if I am putting this in the right place. But this is the fix I tried.
@Bean
ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
return objectMapper;
}
I put it in the SwaggerDocumentationConfig
.
In general, I don't understand why this generated code is so buggy.
https://github.com/FasterXML/jackson-modules-java8/issues/219
serialize/deserialize java 8 java.time with Jackson JSON mapper
How should I fix this?