I have a custom ObjectMapper
configured within my application which has custom modules for deserializing immutable types provided by Guava in Jackson.
My problem is that I cannot seem to override the objectMapper
use by @StreamListener
such that it deserializes my objects correctly.
Here is what I have tried:
@Bean
public MessageConverter messageConverter() {
final MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter();
mappingJackson2MessageConverter.setObjectMapper(objectMapper);
return mappingJackson2MessageConverter;
}
The above snippet is in a class annotated with @Configuration
and the objectMapper
is defined in the class:
public static final ObjectMapper objectMapper = new ObjectMapper()
.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES))
.registerModule(new GuavaModule());
Any ideas on what I may be missing?
So, it turns out there was no issue with my configuration. My custom ObjectMapper
was being selected by the MappingJackson2MessageConverter
. However, the message converter was not being selected, because the messages were being sent with the wrong content-type header.
Moral of the story, be careful with the Content-Type and make sure it matches the converter.