I am attempting to switch from Gson to Jackson in a Spring 4 (non Boot) web application. For a number of reasons, I am still using XML application configuration to define my beans. No matter what I try, I cannot seem to get Jackson's ObjectMapper
or any related factory to be available for injection into my target class. Here is the error I get:
NoSuchBeanDefinitionException: No qualifying bean of type 'com.fasterxml.jackson.databind.ObjectMapper' available
I have tried the following two configurations, which do not work:
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">
</bean>
</property>
</bean>
// java code
@Autowired
private Jackson2ObjectMapperBuilder objectMapper;
and:
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="serializationInclusion" value="NON_NULL"/>
</bean>
</property>
</bean>
// java code
@Autowired
private ObjectMapper objectMapper;
I have read many questions here on Stack Overflow, but most answers assume either that the reader is using Boot, or that he does not want to use the old school XML configuration. Unfortunately in my case, I am using XML, and I am not using Boot.