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/http://ift.tt/1Iyd7QW": 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'
Aucun commentaire:
Enregistrer un commentaire