Reputation: 3586
I want to use the default ObjectMapper almost everywhere in my application. However, there is a specific request that I need to sent to a third party that requires different ObjectMapper.
There are lots of posts on how to customize the default mapper, but I was not able to find a single one explaining how to add an ObjectMapper without replacing the default one.
I tried adding @Qualifier, adding a name to the @Bean, even creating a new class that subclasses ObjectMapper, to no avail. As soon as I add any kind of ObjectMapper, the default one always gets replaced.
Can someone provide an example of how to do this?
Upvotes: 2
Views: 936
Reputation: 59699
Don't let Spring manage it - Just new it up where you need it.
All of the Spring auto configuration for Jackson will back off when you supply an ObjectMapper
bean. As an alternative, you can also @Autowire
in Jackson2ObjectMapperBuilder
, which the Jackson auto configuration uses to create the default ObjectMapper instance. Invoke Jackson2ObjectMapperBuilder#build
to create a new ObjectMapper
instance.
Upvotes: 1