Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending Jackson2JsonMessageConverter #589

Closed
calvernaz opened this issue Mar 15, 2017 · 1 comment
Closed

Extending Jackson2JsonMessageConverter #589

calvernaz opened this issue Mar 15, 2017 · 1 comment
Assignees

Comments

@calvernaz
Copy link

calvernaz commented Mar 15, 2017

I want to register a new module into the object mapper present in Jackson2JsonMessageConverter, but the documentation suggests two ways of doing it:

  • One is to configure the ObjectMapper and inject into Jackson2JsonMessageConverter. The documentation in the setJsonObjectMapper suggest an alternative which is to extend the class and override the method initializeJsonObjectMapper

  • The issue with extending the Jackson2JsonMessageConverter is the lack of access to the ObjectMapper in the parent class, ending up like this:

public class JacksonMessageConverter extends Jackson2JsonMessageConverter {
    @Override
    protected void initializeJsonObjectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new GuavaModule());
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        this.setJsonObjectMapper(objectMapper);
    }
}

So we still have to inject the ObjectMapper, besides overriding the method, it doesn't really look like an alternative.

Changing the ObjectMapper visibility to protected (or a getter) would give us the alternative.

@garyrussell
Copy link
Contributor

Yes, it looks like an oversight; there should either be a getter or the mapper should be passed in as an argument to the method.

artembilan added a commit to artembilan/spring-amqp that referenced this issue Mar 27, 2017
@artembilan artembilan self-assigned this Mar 28, 2017
artembilan added a commit that referenced this issue Mar 28, 2017
Fixes #589

* Deprecate `setJsonObjectMapper()` in favor of newly introduced ctor
based on the external `ObjectMapper`
* Deprecate `initializeJsonObjectMapper()` in favor of newly introduced
ctor based on the externally configured `ObjectMapper`
garyrussell pushed a commit that referenced this issue Jul 19, 2017
Fixes #589

* Deprecate `setJsonObjectMapper()` in favor of newly introduced ctor
based on the external `ObjectMapper`
* Deprecate `initializeJsonObjectMapper()` in favor of newly introduced
ctor based on the externally configured `ObjectMapper`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants