문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
springframework:springboot:json [2019/01/11 17:45] 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 는 이값이 **기본 '' |
+ | * **'' | ||
* 이렇게 하면 '' | * 이렇게 하면 '' | ||
{ | { | ||
줄 115: | 줄 119: | ||
}</ | }</ | ||
* '' | * '' | ||
+ | |||
+ | ==== Jackson2ObjectMapperBuilder 사용시 Module 추가 ==== | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
==== @EnableWebMvc ==== | ==== @EnableWebMvc ==== | ||
'' | '' | ||
줄 156: | 줄 165: | ||
==== WebFlux Jackson 설정 ==== | ==== WebFlux Jackson 설정 ==== | ||
* [[springframework: | * [[springframework: | ||
+ | * '' | ||
* https:// | * https:// | ||
<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) { | + | |
- | | + | |
- | | + | |
- | } | + | |
- | }; | + | |
} | } | ||
+ | } | ||
</ | </ | ||
줄 204: | 줄 189: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// |