I would like to replace the default objectMapper of the MappingJacksonHttpMessageConverter.
I found a working solution but I am not happy about it:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<!-- Scans the classpath of this application for @Components to deploy as beans -->
<context:component-scan base-package="org.mypackage.service"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<!--Adding the default message converters-->
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="writeAcceptCharset" value="false"/>
</bean>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
<!--Adding our custom JSON converter-->
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper">
<util:constant static-field="org.mypackage.JsonUtils.MAPPER"/>
</property>
</bean>
</list>
</property>
</bean>
The solution initializes RequestMappingHandlerAdapter classes with my custom list of message converters.
I don't like this solution because I needed to add the default message converters (which I copied from the org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
constructor).
Without adding the default converters - my controllers could handle only application/json requests and forgot how to handle other basic requests such as application/xml.
Thanks.