Provide a way to configure KotlinSerializationJsonDecoder
See original GitHub issueIt seems there isn’t a way to provide a custom Json
or set config on Json
for the KotlinSerializationJsonDecoder
Spring Framework 5.3.14
Workaround:
@Configuration(proxyBeanMethods = false)
class InitConfiguration {
@ExperimentalSerializationApi
@Bean
fun kotlinSerializationJsonDecoder() = KotlinSerializationJsonDecoder(Json {
explicitNulls = false
})
}
@ExperimentalSerializationApi
@Configuration
class WebConfig(val decoder: KotlinSerializationJsonDecoder) : WebFluxConfigurer {
override fun configureHttpMessageCodecs(configurer: ServerCodecConfigurer) {
super.configureHttpMessageCodecs(configurer)
configurer.defaultCodecs().kotlinSerializationJsonDecoder(decoder)
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
ktor with kotlinx serialization: how to use JSON.nonstrict
You can specify json configurations using the Json builder, which you pass into the KotlinxSerializer.
Read more >KotlinSerializationJsonDecoder (Spring Framework 6.0.2 API)
Decode a byte stream into JSON and convert to Object's with kotlinx.serialization. This decoder can be used to bind @Serializable Kotlin classes, ...
Read more >Kotlin Serialization with Spring 5.3 - Vivid Code
Use Serializers Module. If you are using your own serializers module, you need to create your own KotlinSerializationJsonHttpMessageConverter ...
Read more >Hi I have a spring boot application and I m trying to use ko
I think you need to configure KotlinX serialization both for inbound requests ... Json) = KotlinSerializationJsonDecoder(json) @Bean fun exchangeStrategies( ...
Read more >KotlinSerializationJsonDecoder (spring-web 5.3.10 API) - javadoc.io
Decode a byte stream into JSON and convert to Object's with kotlinx.serialization. This decoder can be used to bind @Serializable Kotlin classes, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think you are right about the unnecessary bean but I guess I was hoping for something like
Jackson2ObjectMapperBuilderCustomizer
which provides a nice way to customize Jackson.I just realized that for what I wanted to do I had to take a different approach. I wanted to configure the
kotlinx.serialization
Decoder forWebClient
.I ended up with something close to this:
Based on: https://stackoverflow.com/a/66020393/12249394 and https://discuss.kotlinlang.org/t/kotlinx-serialization-with-spring-boot/16540/15