사용자 도구

사이트 도구


springframework:springboot:json

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
springframework:springboot:json [2019/01/11 17:45]
kwon37xi [WebFlux Jackson 설정]
springframework:springboot:json [2019/01/23 18:19]
kwon37xi [WebFlux Jackson 설정]
줄 115: 줄 115:
 }</code> }</code>
   * ''DateTimeForamtter.ISO_ZONED_DATE_TIME''은 표준이 아니다. jackson은 ''ZonedDateTime''에 대해 기본으로 ''ISO_OFF_SET_DATE_TIME''을 사용한다.   * ''DateTimeForamtter.ISO_ZONED_DATE_TIME''은 표준이 아니다. jackson은 ''ZonedDateTime''에 대해 기본으로 ''ISO_OFF_SET_DATE_TIME''을 사용한다.
 +
 +==== Jackson2ObjectMapperBuilder 사용시 Module 추가 ====
 +  * ''Jackson2ObjectMapperBuilder'' 사용시 모듈을 추가하려면 ''modules'' 메소드 혹은 ''modulesToInstall''를 사용한다.
 +  * ''modules(...)'' : Spring과 Jackson default 모듈 탐색을 모두 취소하고 오직 이 메소드 인자로 전달된 모듈만 탑재
 +  * ''modulesToInstall(...)'' : Spring(JSR-310 or jodatime 등 자동추가)과 Jackson default 모듈 탑재를 수행하고 그 뒤에 명시된 모듈을 추가 탑재
 ==== @EnableWebMvc ==== ==== @EnableWebMvc ====
 ''@EnableWebMvc''와 ''WebMvcConfigurerAdapter''를 사용하는 순간 더이상 SpringBoot가 아니고 Spring 이기 때문에 위의 설정이 먹지 않게 된다. [[springframework:springboot:mvc|SpringBoot and Spring MVC]] 참조 [[https://github.com/spring-projects/spring-boot/issues/2116|Spring Boot Issue 2116]] ''@EnableWebMvc''와 ''WebMvcConfigurerAdapter''를 사용하는 순간 더이상 SpringBoot가 아니고 Spring 이기 때문에 위의 설정이 먹지 않게 된다. [[springframework:springboot:mvc|SpringBoot and Spring MVC]] 참조 [[https://github.com/spring-projects/spring-boot/issues/2116|Spring Boot Issue 2116]]
줄 161: 줄 166:
 <code java> <code java>
 @Configuration @Configuration
-public class Config { +public class Config implements WebFluxConfigurer, Jackson2ObjectMapperBuilderCustomizer 
- +    @Override 
-    @Bean +    public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) { 
-    JavaTimeModule javatimeModule(){ +        jacksonObjectMapperBuilder 
-        return new JavaTimeModule(); +                .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) 
-    } +                .timeZone(TimeZone.getDefault()) 
- +                .locale(Locale.getDefault()) 
-    @Bean +                .simpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
-    Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer(){ +
-    return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.featuresToEnable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) +
-            .mixIn(MyClass.class, MyClassMixin.class); +
-    } +
- +
- +
-    @Bean +
-    Jackson2JsonEncoder jackson2JsonEncoder(ObjectMapper mapper)+
-       return new Jackson2JsonEncoder(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) { +
-                configurer.defaultCodecs().jackson2Encoder(encoder); +
-                configurer.defaultCodecs().jackson2Decoder(decoder); +
-            } +
-        }; +
     }     }
 } }
springframework/springboot/json.txt · 마지막으로 수정됨: 2020/11/23 19:00 저자 kwon37xi