Improvement to allow customization of kotlin serializer in AbstractKotlinSerializationHttpMessageConverter #29761
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found that Page Generic Type does not work with kotlin serialization.
Reference Issue: Issue-28389
As a result of debugging and analysis, I found the following problems.
[Problem]
AbstractKotlinSerializationHttpMessageConverter.serialize()
always returns null, soAbstractKotlinSerializationHttpMessageConverter.canWrite()
will return false. Therefore, KotlinSerialization is ignored byAbstractMessageConverterMethodProcessor.writeWithMessageConverters()
.AbstractKotlinSerializationHttpMessageConverter.serialize()
always return null?Serializer sKt.serializeOrNull()
.KotlinSerializationJsonHttpMessageConverter
does not support open Polymorphic Serialization, null is returned due to thehasPolymorphism()
function.[Temporarily Resolved]
I understood the above problems and solved them by customizing
AbstractKotlinSerializationHttpMessageConverter
and registering it.AbstractKotlinSerializationHttpMessageConverter.serialize()
->CustomKotlinSerializationJsonHttpMessageConverter
classAs a result, it was successful.
[My opinion]
I think it is a very inconvenient process for users to create and register CustomKotlinSerializationHttpMessageConverter as above every time. And since Page, Slice, etc. are the types that users use a lot, the above process will be more inconvenient.
I tried to solve it by forking the Spring-Data-Commons module that owns the Page class, but found out that the access specifier of
AbstractKotlinSerializationHttpMessageConverter.serialize()
was private, so I considered making serializeInternal abstract method.If PR is allowed, I think I can expect the following two effects.
[Plan]