使用Jackson序列化前缀字段名称

时间:2016-05-24 12:34:32

标签: json spring jackson

@前缀添加到@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);
    }
}

1 个答案:

答案 0 :(得分:0)