We would like to disable Kotlin Serialization and ...
# spring
j
We would like to disable Kotlin Serialization and use Jackson until there's streaming support. Is there some way to disable the Kotlin serialization support in Spring? It seems that if we've
kotlinx.serialization.json.Json
in our dependencies it is automatically added.
We managed to do it by changing the default codecs for kotlin serialization through a
ServerCodecConfigurer
for ones that just always return false to canDecode/Encode. But we were wondering if there's a better/cleaner way.
y
as i understand, there are default http message converters that spring add in startup , if kotlinx serialization is in the path it will be added with higher priority than jackson. you can try to remove kotlinx converter from that list with define configuration file that extend from WebMvcConfigurer:
Copy code
@Configuration
class KotlinxSerializationConfig : WebMvcConfigurer {
    override fun extendMessageConverters(converters: MutableList<HttpMessageConverter<*>>) {
        converters.removeIf { it is KotlinSerializationJsonHttpMessageConverter }
    }
}
i didn’t tested it, but it should work
j
Thanks Yevgeni, I'll try it
273 Views