2

I'm trying to have my camelCased variable names serialized to underscore names by Jackson2; e.g. accessToken => access_token.

After doing some research, I made the following changes. In applicationContext xml,

<mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper">
                <bean class="com.company.core.util.JsonMapper"/>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

In my custom object mapper,

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;

import javax.inject.Named;

@Named
public class JsonMapper extends ObjectMapper {
  public JsonMapper() {
    setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
  }
}

Here's the error log:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.http.converter.json.MappingJackson2HttpMessageConverter#0' defined in "/C:/DevTools/jboss-eap-6.3/bin/content/platform-security-0.1.war/WEB-INF/classes/spring/applicationContext-security.xml": Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.company.core.util.JsonMapper' to required type 'com.fasterxml.jackson.databind.ObjectMapper' for property 'objectMapper'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.company.core.util.JsonMapper] to required type [com.fasterxml.jackson.databind.ObjectMapper] for property 'objectMapper': no matching editors or conversion strategy found

Am I missing a jar file somewhere? (These are only the ones that seem relevant.)

compile 'aopalliance:aopalliance:1.0'
compile 'javax.activation:activation:1.1'
compile 'org.jboss.resteasy:resteasy-client:3.0.9.Final'
compile 'org.jboss.resteasy:resteasy-jackson2-provider:3.0.9.Final'
compile 'org.jboss.resteasy:resteasy-spring:3.0.9.Final'
compile 'org.springframework:spring-core:4.1.3.RELEASE'
compile 'org.springframework:spring-aop:4.1.3.RELEASE'
compile 'org.springframework:spring-beans:4.1.3.RELEASE'
compile 'org.springframework:spring-context:4.1.3.RELEASE'
compile 'org.springframework:spring-web:4.1.3.RELEASE'
compile 'org.springframework:spring-webmvc:4.1.3.RELEASE'
compile 'com.fasterxml.jackson.core:jackson-core:2.5.0'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.0'
Stephen
  • 31
  • 1
  • 3
  • The Spring converter seems unnecessary, as that's what `resteasy-jackson2-provider` is for in a JAX-RS environment. You can configure the `ObjectMapper` in a `ContextResolver` as [seen here](http://stackoverflow.com/a/29527901/2587435) – Paul Samsotha Apr 10 '15 at 06:06
  • You might without the direct `jackson-*` references. `resteasy-jackson2-provider` already (transitively) depends on jackson. – dhke Apr 10 '15 at 06:07

0 Answers0