com.infobip.kafkistry.webapp.ApiSerializationConfig.kt Maven / Gradle / Ivy
package com.infobip.kafkistry.webapp
import com.fasterxml.jackson.annotation.JsonAutoDetect
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.kotlinModule
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
@Configuration
class ApiSerializationConfig {
@Bean
fun mappingJackson2HttpMessageConverter(): MappingJackson2HttpMessageConverter {
val jsonConverter = MappingJackson2HttpMessageConverter()
val objectMapper = Jackson2ObjectMapperBuilder()
.modules(kotlinModule())
.build()
.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.ANY)
.setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
jsonConverter.objectMapper = objectMapper
return jsonConverter
}
}