自定义JSON ObjectMapper:找不到匹配的编辑器或转换策略

时间:2016-01-27 10:39:30

标签: java json jackson

我正在尝试创建自定义ObjectMapper但遇到问题。我想在序列化期间使用Enum的toString方法:

XML配置:

<bean id="restTemplateMS"     class="org.springframework.web.client.RestTemplate">
    <constructor-arg ref="httpClientFactory" />
    <property name="messageConverters">
        <list>
            <bean
                class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>somethio</value>
                    </list>
                </property>
                <property name="objectMapper" ref="customObjectMapper"/>
            </bean>
        </list>
    </property>
</bean>
<bean id="customObjectMapper" class="com.mag.xxx.CustomJsonObjectMapper"/>

爪哇:

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
public class CustomJsonObjectMapper extends ObjectMapper
{

public CustomJsonObjectMapper()
{
    super();
    this.configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, true);
}
}

错误:

Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.mag.xxx.CustomJsonObjectMapper] to required type [org.codehaus.jackson.map.ObjectMapper] for property 'objectMapper': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470)

0 个答案:

没有答案