-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Introduce Kotlin Serialization auto-configuration #46546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Kotlin Serialization auto-configuration #46546
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a workaround to prevent the CheckAutoConfigurationClasses
task from failing. The issue is that the Kotlin Gradle Plugin adds a kotlin
SourceDirectorySet
to the main
SourceSet
even when there are no Kotlin source files. As a result, the CheckAutoConfigurationClasses
task throws an IOException
when it tries to walk through the /build/classes/kotlin/main
directory, which doesn't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not the ideal solution, it would be better to address the issue in the CheckAutoConfigurationClasses
task itself by filtering out the Kotlin directory from the scan.
78f9e3b
to
5928326
Compare
5928326
to
7d141fb
Compare
See spring-projects#44241 Signed-off-by: Dmitry Sulman <dmitry.sulman@gmail.com>
7d141fb
to
cdbbc8c
Compare
Uh oh!
There was an error while loading. Please reload this page.
This PR adds auto-configuration support for Kotlin Serialization in Spring Boot, addressing spring-projects/spring-boot#44241
Summary of Changes
spring-boot-kotlin-serialization
, which providesKotlinSerializationAutoConfiguration
. This auto-configuration supports a set of new properties under thespring.kotlin-serialization
prefix for customizing the Json instance fromkotlinx.serialization
.spring-boot-starter-kotlin-serialization
.KotlinSerializationHttpMessageConvertersConfiguration
inspring-boot-http-converter
.kotlin-serialization
option to thespring.http.converters.preferred-json-mapper
property to exposeKotlinSerializationJsonHttpMessageConverter
as a bean.HttpMessageConverters
configuration to addKotlinSerializationJsonHttpMessageConverter
immediately beforeMappingJackson2HttpMessageConverter
. This restores the behavior prior to the Spring Framework change whenspring.http.converters.preferred-json-mapper=kotlin-serialization
is explicitly set.kotlin-serialization
option and configuration support.There was a suggestion in the original issue to use
kotlinx
as the option name. However,kotlinx
is a general namespace used across many Kotlin libraries (likekotlinx.coroutines
,kotlinx-datetime
,kotlinx-io
), not just for serialization. To avoid confusion and be more specific, I chose to usekotlin-serialization
both in the code (KotlinSerialization*
classes) and as the value for thespring.http.converters.preferred-json-mapper
property. This keeps the naming clear and consistent.Let me know if anything needs to be changed or improved, happy to adjust things if needed.
Fixes #44241