2016-07-07 4 views
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} 

私は間違っていますか?

答えて

0

私は4.2.6 RELEASEに私の春のプロジェクトのバージョンを更新しました。それが私の問題を解決しました。

0

は、コンストラクタに次の行を追加してください:

this.setDateFormat(new ISO8601DateFormat()); 
+0

いいえこの設定では動作しません – Gabriel

+0

詳しいことはありますか?日付は同じ方法でまだシリアル化されていますか?また、このカスタムマッパーを使用しているプロビジョニングコードはありますか? – mdziob

+0

はい同じ方法で日付をシリアル化しています。このカスタムマッパーは春に使用されていますが、私はSpringのObjectMapperをオーバーライドしてCustomJacksonMapperを使用しました – Gabriel

関連する問題