3
我使用Spring REST框架和杰克逊JSON@XmlJavaTypeAdapter不与杰克逊JSON工作
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper" ref="customObjectMapper" />
<property name="supportedMediaTypes" value="application/json" />
</bean>
<bean id="customObjectMapper"class="com.rackspace.payment.webapp.utils.JaxbJacksonObjectMapper" />
public class JaxbJacksonObjectMapper extends ObjectMapper {
@SuppressWarnings("deprecation")
public JaxbJacksonObjectMapper() {
final AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
this.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
super.getDeserializationConfig().withAnnotationIntrospector(introspector);
this.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRITE_NULL_PROPERTIES, false);
this.configure(org.codehaus.jackson.map.SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
super.getSerializationConfig().withAnnotationIntrospector(introspector);
}
}
//JXAB element
@XmlAttribute(name = "createDate")
@XmlJavaTypeAdapter(CustomDateAdapter.class)
protected Date createDate;
我所面临的问题是,将显示JSON输出时“CREATEDATE”元素的显示如同串XML适配器类不会被调用,但它在XML输出中工作正常。
我错过了什么?如何以JSON格式调用XmlJavaTypeAdapter。
解决了这个问题,这个环节的帮助http://stackoverflow.com/questions/9517189/spring-mvc-and-jackson-mapping-do-not-return-the-root-element-in -json – spal