Skip to content
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

Request to improve KotlinSerializationJsonHttpMessageConverter logic in RestTemplate #29008

Closed
meloning opened this issue Aug 24, 2022 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: bug A general bug
Milestone

Comments

@meloning
Copy link
Contributor

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.

image

I can temporarily solve it like the configuration below.
image
image

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.
image

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

please check.
thank you

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 24, 2022
@meloning
Copy link
Contributor Author

meloning commented Aug 24, 2022

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.
image
image

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

Please allow RestTemplate to use Kotlinx.Serialization by default.

@sdeleuze sdeleuze self-assigned this Aug 24, 2022
@sdeleuze sdeleuze added this to the 5.3.23 milestone Sep 2, 2022
@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug theme: kotlin An issue related to Kotlin support and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 2, 2022
@meloning
Copy link
Contributor Author

meloning commented Sep 21, 2022

@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.

@sdeleuze
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants