spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
73.85k stars 40.36k forks source link

Add auto-configuration for kotlinx.serialization #24238

Open neostage opened 3 years ago

neostage commented 3 years ago

using Spring Boot 2.4.0) spring-boot-starter-actuator has strong dependencies on jackson so that I can't use kotlinx.serialization as default json message converter.

sdeleuze commented 3 years ago

Hi, thanks for raising this since indeed I think there is a need for a proper integration for Kotlin serialization in Boot that goes further than what is inherited from Spring Framework.

Current behavior is documented here and has several limitations in Boot context that we would be likely to improve.

The configuration is kind of Spring Framework oriented, a dedicated Boot support similar to JSON-B and related documentation would be much better for consistency.

The second point that should be improved is what you raised in the issue. After discussing with @bclozel I tend to think it is currently not straightforward to support Kotlin serialization and actuators because the web configuration is shared between your app (that wants to use Kotlin serialization) and and actuator (that needs Jackson or similar general purpose JSON library to be configured in your web configuration. And Kotlin serialization is designed to serialize only Kotlin classes annotated with @Serializable or collection of those.

On Framework side, maybe I could refine the converter selection mechanism to have a better support for having both Kotlin Serialization and Jackson via https://github.com/spring-projects/spring-framework/issues/26147 in order to provide a workaround with manual config of both.

On Boot side, after discussing with @snicoll and @bclozel , it sounds like a candidate for Spring Boot 2.5 that would potentially involve the resolution of #20291. As well as dependency management (I am discussing the creation of a Kotlin serialization BOM with the Kotlin team).

neostage commented 3 years ago

Thanks for the detailed response and I'll look forward to future releases!

sdeleuze commented 3 years ago

@snicoll After working on a draft commit for spring-projects/spring-framework#26147, I confirm that I plan to configure both Kotlin serialization and Jackson when they are on the classpath, I think that's will make configuration easier and will make actuator and error endpoints still working. Kotlin serialization is more narrow so that seems to work as expected.

So for Boot 2.5, what would be mainly needed is autoconfiguration and documentation à la JSONB, and dependency management with the upcoming BOM that I have asked to Kotlin team (similar to Coroutines one).

snicoll commented 3 years ago

Thanks for the follow-up Sébastien. I've repurposed this issue and triaged it for 2.5.x.

sdeleuze commented 3 years ago

@neostage I have fixed spring-projects/spring-framework#26147 and made sure your use case work fine with Boot 2.4, please test Spring Framework 5.3.2-SNAPSHOT with both Jackson and Kotlin serialization in the classpath it should work as expected.