Affects: 5.3.22 (below 5.3.22)


Hello, I was using the Kotlinx.serialization module well because of Spring registered KotlinSerializationJsonHttpMessageConverter through WebMvcConfigurationSupport.addDefaultHttpMessageConverters

However, even though I added the Kotlinx.Serialization module, it was not available in RestTemplate.

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0")

After analyzing why, only Jackson, which is the default serialization, was registered due to the if-else if logic as shown below, so Kotlinx.Serialization could not be used.

Spring Request to improve KotlinSerializationJsonHttpMessageConverter logic in RestTemplate

I can temporarily solve it like the configuration below. Spring Request to improve KotlinSerializationJsonHttpMessageConverter logic in RestTemplate Spring Request to improve KotlinSerializationJsonHttpMessageConverter logic in RestTemplate

I solved it, but I think it is very inconvenient to have to add KotlinSerializationJsonHttpMessageConverter to use kotlinx.serialization.

I as with WebMvcConfigurationSupport.addDefaultHttpMessageConverters, when the Kotlinx.Serialization module does not exist, it is hoped that Jackson2 Serialization will be used by default. Spring Request to improve KotlinSerializationJsonHttpMessageConverter logic in RestTemplate

I'm going to post a PR on this issue.

please check. thank you

Comment From: meloning

Additionally, I checked the comments on RestTemplate to consider using WebClient.

NOTE: As of 5.0 this class is in maintenance mode, with only minor requests for changes and bugs to be accepted going forward. Please, consider using the org.springframework.web.reactive.client.WebClient which has a more modern API and supports sync, async, and streaming scenarios.

I checked the KotlinSerialization operation through the BaseDefaultCodecs.initObjectReaders method. Spring Request to improve KotlinSerializationJsonHttpMessageConverter logic in RestTemplate Spring Request to improve KotlinSerializationJsonHttpMessageConverter logic in RestTemplate

I am hoping to use KotlinSerialization in RestTemplate without much setup.

Please allow RestTemplate to use Kotlinx.Serialization by default.

Comment From: meloning

@sdeleuze Hello, Thank you for checking the issue and merging. I am very happy that finally it is deployed. However, I am asking because I am not included as a contributor in the release notes. If you're okay, please add me as a contributor to the release notes.

Comment From: sdeleuze

Sure, done not sure why that was missed. Thanks for your contribution.