-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from whatever-mentoring/feature/fix-jackson-co…
…nfig Implement GoalBettingObjectMapperBuilderCustomizer
- Loading branch information
Showing
2 changed files
with
28 additions
and
20 deletions.
There are no files selected for viewing
24 changes: 4 additions & 20 deletions
24
raisedragon-api/src/main/kotlin/com/whatever/raisedragon/config/JacksonConfig.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Jackson2ObjectMapperBuilderCustomizer>): 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() | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../main/kotlin/com/whatever/raisedragon/jackson/GoalBettingObjectMapperBuilderCustomizer.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} | ||
} |