将@
前缀添加到@XmlAtrribute
的最简单方法是什么?带杰克逊序列化到JSON的带注释字段名称?现在,@XmlElement
和@XmlAttribute
都以相同的方式转换。我的目标是将属性与JSON中的元素区分开来。
Spring beans config:
<bean id="jackson2HttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"
autowire-candidate="false">
<property name="objectMapper" ref="messageObjectMapper"/>
</bean>
ObjectMapper config:
public class MessageObjectMapper extends ObjectMapper implements InitializingBean {
private boolean indentOutput = false;
public void setIndentOutput(boolean indentOutput) {
this.indentOutput = indentOutput;
}
public MessageObjectMapper() {
super();
this.registerModule(new JodaModule());
this.setSerializationInclusion(JsonInclude.Include.NON_NULL);
this.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
this.setTimeZone(TimeZone.getDefault());
}
@Override
public void afterPropertiesSet() throws Exception {
this.configure(SerializationFeature.INDENT_OUTPUT, this.indentOutput);
}
}
答案 0 :(得分:0)
最后Jackson MixIns为我工作。
http://wiki.fasterxml.com/JacksonMixInAnnotations
我使用过Jackson 2.7.4和本教程的语法: http://www.leveluplunch.com/java/tutorials/024-modifying-fields-external-domain-jackson-mixin/