I am getting an error in a spring boot rest api because spring does not handle serialization of org.joda.time.Days.
org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class org.joda.time.Days]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Joda date/time type `org.joda.time.Days` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-joda" to enable handling (through reference chain: java.util.ArrayList[4]->io.nflow.rest.v1.msg.ListWorkflowDefinitionResponse["settings"]->io.nflow.rest.v1.msg.ListWorkflowDefinitionResponse$Settings["historyDeletableAfter"])
I have exhausted all resources on Stack Overflow, and I have followed the advice given in the exception. I have added the following to my Spring Boot application:
@Bean
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
logger.info("Json customizer invoked.");
return builder -> builder.modules(new JodaModule());
}
And the following dependency to the pom.xml:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
And still I get the above error. I am out of ideas and options. How do we get spring-boot to handle org.joda.time.Days? this class is an implementation of the interface: ReadablePeriod. JodaModule has an entry in it's constructor as follows:
addDeserializer(ReadablePeriod.class, new PeriodDeserializer(false));
What will it take for spring to be able to handle org.joda.time.Days as one would expect given the current documentation and available help?
Comment From: bclozel
Could you share a minimal, sample application that reproduces the issue?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
Comment From: zelaskoa
@steowens could you fix the problem ? I have same issue
Comment From: zelaskoa
@steowens i could resolve it by explicit setting a Json Encoder/Decoder to the Webclient
ExchangeStrategies strategies =
ExchangeStrategies.builder()
.codecs(
clientDefaultCodecsConfigurer -> {
clientDefaultCodecsConfigurer
.defaultCodecs()
.jackson2JsonEncoder(
new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON));
clientDefaultCodecsConfigurer
.defaultCodecs()
.jackson2JsonDecoder(
new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON));
})
.build();
return WebClient.builder()
.exchangeStrategies(strategies)
.build();
Comment From: javieraviles
You can also configure Jackson explicitly by creating a Jackson2ObjectMapperBuilderCustomizer bean in your application configuration:
@Configuration
public class JacksonConfig {
@Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() {
return builder -> {
builder.featuresToEnable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
builder.modules(new JodaModule());
};
}
}