Last active
April 7, 2020 02:57
-
-
Save ksundong/3246e3e01d9ec9b201a49424699eaded to your computer and use it in GitHub Desktop.
Jackson Config (DateTime 표시형식 설정)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; | |
| import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | |
| import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer; | |
| import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.context.annotation.Configuration; | |
| import java.time.format.DateTimeFormatter; | |
| import java.util.TimeZone; | |
| @Configuration | |
| public class JacksonConfig { | |
| private static final String dateFormat = "yyyy-MM-dd"; | |
| private static final String dateTimeFormat = "yyyy-MM-dd HH:mm:ss"; | |
| private static final String timeZone = "Asia/Seoul"; | |
| @Bean | |
| public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() { | |
| return builder -> { | |
| builder.simpleDateFormat(dateTimeFormat); | |
| builder.serializers(new LocalDateSerializer(DateTimeFormatter.ofPattern(dateFormat))); | |
| builder.serializers(new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat))); | |
| builder.serializers(new ZonedDateTimeSerializer(DateTimeFormatter.ofPattern(dateTimeFormat))); | |
| builder.timeZone(TimeZone.getTimeZone(timeZone)); | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment