문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
springframework:springboot:json [2019/01/11 19:26] kwon37xi [모든 타입에 대해 일관성 있는 커스텀 형식 지원] |
springframework:springboot:json [2020/11/23 19:00] (현재) kwon37xi [WRITE_DATES_AS_TIMESTAMPS=false 사용] |
||
|---|---|---|---|
| 줄 7: | 줄 7: | ||
| ==== 기본 설정 ==== | ==== 기본 설정 ==== | ||
| - | * 의존성에 다음 추가해야 JSR310 날짜/ | + | * SpringBoot 2.x 는 starter 추가 하면 Jackson '' |
| + | api ' | ||
| + | </ | ||
| + | * 구버전 SpringBoot 에서는 | ||
| compile(' | compile(' | ||
| compile(' | compile(' | ||
| 줄 42: | 줄 45: | ||
| spring.jackson.serialization.write-dates-as-timestamps: | spring.jackson.serialization.write-dates-as-timestamps: | ||
| </ | </ | ||
| - | * SpringBoot 2.x 는 이값이 **기본 '' | + | * SpringBoot 2.x 는 이값이 **기본 '' |
| + | * **'' | ||
| * 이렇게 하면 '' | * 이렇게 하면 '' | ||
| { | { | ||
| 줄 166: | 줄 170: | ||
| <code java> | <code java> | ||
| @Configuration | @Configuration | ||
| - | public class Config { | + | public class Config |
| - | + | @Override | |
| - | @Bean | + | |
| - | | + | |
| - | | + | .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) |
| - | } | + | .timeZone(TimeZone.getDefault()) |
| - | + | .locale(Locale.getDefault()) | |
| - | @Bean | + | .simpleDateFormat(" |
| - | Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer(){ | + | |
| - | return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.featuresToEnable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | + | |
| - | .mixIn(MyClass.class, MyClassMixin.class); | + | |
| - | } | + | |
| - | + | ||
| - | + | ||
| - | @Bean | + | |
| - | Jackson2JsonEncoder jackson2JsonEncoder(ObjectMapper mapper){ | + | |
| - | | + | |
| - | } | + | |
| - | + | ||
| - | @Bean | + | |
| - | Jackson2JsonDecoder jackson2JsonDecoder(ObjectMapper mapper){ | + | |
| - | return new Jackson2JsonDecoder(mapper); | + | |
| - | } | + | |
| - | + | ||
| - | @Bean | + | |
| - | WebFluxConfigurer webFluxConfigurer(Jackson2JsonEncoder encoder, Jackson2JsonDecoder decoder){ | + | |
| - | return new WebFluxConfigurer() { | + | |
| - | @Override | + | |
| - | public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { | + | |
| - | | + | |
| - | | + | |
| - | } | + | |
| - | }; | + | |
| } | } | ||
| } | } | ||
| 줄 211: | 줄 189: | ||
| * [[https:// | * [[https:// | ||
| * [[https:// | * [[https:// | ||
| + | * [[https:// | ||