2

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?

  • Spring Boot: 1.5.10.RELEASE
  • Spring Rabbit: 1.7.6.RELEASE
  • Spring Cloud Stream: 1.2.2.RELEASE
  • Spring Messaging: 4.3.14.RELEASE
Brian
  • 168
  • 1
  • 6
  • You are using older releases. Can you try upgrading to Spring Cloud Stream 2.0.x release (which requires Boot 2.0.x)? – sobychacko Aug 16 '18 at 14:51
  • @sobychacko, if I had that as an easy option, I would definitely do that. However, I am trying to solve this for the current version stack. – Brian Aug 16 '18 at 16:20

1 Answers1

2

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.

Brian
  • 168
  • 1
  • 6