From bb10fe5882964adb2a929fabd09c0cd92dc4ad69 Mon Sep 17 00:00:00 2001 From: "Jaemin.Park" Date: Wed, 10 Jul 2024 20:28:00 +0900 Subject: [PATCH] Implement GoalBettingObjectMapperBuilderCustomizer --- .../raisedragon/config/JacksonConfig.kt | 24 ++++--------------- ...oalBettingObjectMapperBuilderCustomizer.kt | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 raisedragon-api/src/main/kotlin/com/whatever/raisedragon/jackson/GoalBettingObjectMapperBuilderCustomizer.kt diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/config/JacksonConfig.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/config/JacksonConfig.kt index a1a4781..b7799a3 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/config/JacksonConfig.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/config/JacksonConfig.kt @@ -1,30 +1,14 @@ package com.whatever.raisedragon.config -import com.fasterxml.jackson.databind.DeserializationFeature -import com.fasterxml.jackson.databind.SerializationFeature -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer -import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer -import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer +import com.whatever.raisedragon.jackson.GoalBettingObjectMapperBuilderCustomizer import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder -import java.time.LocalDate -import java.time.LocalDateTime -import java.time.LocalTime -import java.time.format.DateTimeFormatter @Configuration class JacksonConfig { + @Bean - fun jackson2ObjectMapperBuilder(customizers: List): Jackson2ObjectMapperBuilder { - val builder = Jackson2ObjectMapperBuilder() - .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) - .featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) - .serializerByType(LocalDateTime::class.java, LocalDateTimeSerializer(DateTimeFormatter.ISO_LOCAL_DATE_TIME)) - .serializerByType(LocalDate::class.java, LocalDateSerializer(DateTimeFormatter.ISO_LOCAL_DATE)) - .serializerByType(LocalTime::class.java, LocalTimeSerializer(DateTimeFormatter.ISO_LOCAL_TIME)) - customizers.forEach { customizer -> customizer.customize(builder) } - return builder + fun goalBettingObjectMapperBuilderCustomizer(): GoalBettingObjectMapperBuilderCustomizer { + return GoalBettingObjectMapperBuilderCustomizer() } } \ No newline at end of file diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/jackson/GoalBettingObjectMapperBuilderCustomizer.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/jackson/GoalBettingObjectMapperBuilderCustomizer.kt new file mode 100644 index 0000000..8de741f --- /dev/null +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/jackson/GoalBettingObjectMapperBuilderCustomizer.kt @@ -0,0 +1,24 @@ +package com.whatever.raisedragon.jackson + +import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer +import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.format.DateTimeFormatter + +class GoalBettingObjectMapperBuilderCustomizer : Jackson2ObjectMapperBuilderCustomizer { + override fun customize(jacksonObjectMapperBuilder: Jackson2ObjectMapperBuilder) { + jacksonObjectMapperBuilder + .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .serializerByType(LocalDateTime::class.java, LocalDateTimeSerializer(DateTimeFormatter.ISO_LOCAL_DATE_TIME)) + .serializerByType(LocalDate::class.java, LocalDateSerializer(DateTimeFormatter.ISO_LOCAL_DATE)) + .serializerByType(LocalTime::class.java, LocalTimeSerializer(DateTimeFormatter.ISO_LOCAL_TIME)) + } +} \ No newline at end of file