Created
December 22, 2018 03:22
-
-
Save wmira/b3f0711d45727c743809f8d5362ee48c to your computer and use it in GitHub Desktop.
Kotlin SpringBoot Json
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
import com.fasterxml.jackson.databind.DeserializationFeature | |
import com.fasterxml.jackson.databind.ObjectMapper | |
import com.fasterxml.jackson.databind.SerializationFeature | |
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | |
import org.springframework.context.annotation.Bean | |
import org.springframework.context.annotation.Configuration | |
@Configuration | |
class Json { | |
@Bean | |
fun objectMapper(): ObjectMapper = defaultMapper() | |
companion object { | |
fun defaultMapper(): ObjectMapper = jacksonObjectMapper() | |
.findAndRegisterModules() | |
// toJson() | |
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | |
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) | |
// fromJson() | |
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | |
.disable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT) | |
.disable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT) | |
.disable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) | |
.enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES) | |
.enable(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment