1
は私が作った構成は以下のとおりです。設定が春に取り組んでいない。ここで4.1.5
私のconfigファイル:
<mvc:annotation-driven>
<mvc:message-converters>
<!-- Support for Joda Time -->
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper" ref="customJacksonMapper" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
私のクラスオブジェクト
を拡張@Component("customJacksonMapper")
public class CustomJacksonMapper extends ObjectMapper {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/**
* Instantiates a new custom jackson mapper.
*
* RegisterModule = Registar o módulo do JodaTime.
* Locale = Padrão portugues Brasil.
* TimeZone = Converte para o timezone de São Paulo.
*
*/
public CustomJacksonMapper() {
this.registerModule(new JodaModule());
this.setLocale(new Locale("pt_BR"));
this.setTimeZone(TimeZone.getTimeZone("America/Sao_Paulo"));
this.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS , false);
this.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
}この構成で
、私はポストの多くに読んだとして、日付は正しい形式で返されますが、私は次のようになります:
{"date": 1467920285301}
私は間違っていますか?
いいえこの設定では動作しません – Gabriel
詳しいことはありますか?日付は同じ方法でまだシリアル化されていますか?また、このカスタムマッパーを使用しているプロビジョニングコードはありますか? – mdziob
はい同じ方法で日付をシリアル化しています。このカスタムマッパーは春に使用されていますが、私はSpringのObjectMapperをオーバーライドしてCustomJacksonMapperを使用しました – Gabriel