2017-02-15 12 views
0

私はSpring Bootのないプロジェクトを持っていますが、 "spring data"や "spring data rest"のようないくつかのSpringモジュールを使用しています。Spring Data Restとjava.timeのシリアル化

私はjava.time。*フィールドのシリアル化にいくつかの問題があります。 私はthisのようないくつかのチュートリアルを見つけたが、私は私のRepositoryRestConfigurerAdapter

@Component public class CvlRepositoryRestConfigurerAdapter extends RepositoryRestConfigurerAdapter { 

@Override 
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { 
    config.setDefaultPageSize(75); 
    config.setReturnBodyForPutAndPost(Boolean.TRUE); 
} 

@Override 
public void configureJacksonObjectMapper(ObjectMapper objectMapper) { 
    super.configureJacksonObjectMapper(objectMapper); 
    objectMapper.configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false); 
} 

}

に次の依存

<dependency> 
    <groupId>com.fasterxml.jackson.datatype</groupId> 
    <artifactId>jackson-datatype-jsr310</artifactId> 
    <version>${jackson.version}</version> 
</dependency> 

し、次のコードを追加しても、私の実際の応答には、Javaに関する。時間フィールドは次のようになります

"rateDate":{ "年」:2017、 "月": "2月"、 "DAYOFMONTH":14、 "のdayOfWeek": "火曜日"、 "時代": "CE"、 "DAYOFYEAR":45、 "leapYear" :偽、 "monthValue":2、 "年表":{ "ID": "ISO"、 "calendarType": "ISO8601" }

私が間違ってやっていますか?私は何を忘れているのですか?

答えて

0

ここに私のアダプター。今では

@Component 
public class CvlRepositoryRestConfigurerAdapter extends RepositoryRestConfigurerAdapter { 

@Override 
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { 
    config.setDefaultPageSize(75); 
    config.setReturnBodyForPutAndPost(Boolean.TRUE); 
} 

@Override 
public void configureJacksonObjectMapper(ObjectMapper objectMapper) { 
    super.configureJacksonObjectMapper(objectMapper); 
    objectMapper.configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false); 
    SimpleModule sm = new SimpleModule("jsr310module"); 
    sm.addSerializer(LocalDate.class,new LocalDateSerializer(DateTimeFormatter.ISO_DATE)); 
    sm.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ISO_DATE)); 
    sm.addSerializer(LocalDateTime.class,new LocalDateTimeSerializer(DateTimeFormatter.ISO_DATE_TIME)); 
    sm.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ISO_DATE_TIME)); 
    objectMapper.registerModule(sm); 
} 

}

を働いている私は、すべての罰金になります(デフォルトでUTF-8のようです)のタイムゾーン(ZonedDateTimeフィールド)とエンコーディングをチェックする必要があります。 誰かに役立つことを願っています

関連する問題