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

Spring using kotlin serialization over jackson for its own classes #26321

Closed
tomfi opened this issue Dec 28, 2020 · 1 comment
Closed

Spring using kotlin serialization over jackson for its own classes #26321

tomfi opened this issue Dec 28, 2020 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: regression A bug that is also a regression

Comments

@tomfi
Copy link

tomfi commented Dec 28, 2020

Affects: 5.3.2

In my project I am using kotlin serialization internally for kotlin data classes but expected spring/spring-boot to use jackson as HTTP message converter which was fine until i tried to upgrade from spring boot 2.4.0 to 2.4.1.

After the upgrade, my unit tests failed with the following exception;

2020-12-28 09:15:12.624 ERROR 4263 --- [           main] o.s.s.o.provider.endpoint.TokenEndpoint  : Handling error: HttpMessageNotWritableException, Could not write JSON: Class 'DefaultOAuth2AccessToken' is not registered for polymorphic serialization in the scope of 'OAuth2AccessToken'.
Mark the base class as 'sealed' or register the serializer explicitly.; nested exception is kotlinx.serialization.SerializationException: Class 'DefaultOAuth2AccessToken' is not registered for polymorphic serialization in the scope of 'OAuth2AccessToken'.
Mark the base class as 'sealed' or register the serializer explicitly.

org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Class 'DefaultOAuth2AccessToken' is not registered for polymorphic serialization in the scope of 'OAuth2AccessToken'.
Mark the base class as 'sealed' or register the serializer explicitly.; nested exception is kotlinx.serialization.SerializationException: Class 'DefaultOAuth2AccessToken' is not registered for polymorphic serialization in the scope of 'OAuth2AccessToken'.
Mark the base class as 'sealed' or register the serializer explicitly.
	at org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter.encode(KotlinSerializationJsonHttpMessageConverter.java:161)
	at org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter.writeInternal(KotlinSerializationJsonHttpMessageConverter.java:145)
	at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:104)

Looking further and debugging i found the following change: 43faa43

To be more precise the order of message converters changed between 5.3.1 and 5.3.2:

I tried to find a way to change the order in a simple way or disable kotlin serialization for spring without success. I would like to avoid registering the message converters manually if possible.

Is there a way to workaroud the issue?
Is it intentional that kotlin serialization will be used for classes that are not marked as @Serializable and further then that classes that are internal to spring?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 28, 2020
@jhoeller jhoeller added in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression labels Dec 28, 2020
@jhoeller jhoeller added this to the 5.3.3 milestone Dec 28, 2020
@sdeleuze sdeleuze added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 4, 2021
@sdeleuze sdeleuze removed this from the 5.3.3 milestone Jan 4, 2021
@sdeleuze
Copy link
Contributor

sdeleuze commented Jan 4, 2021

Likely a duplicate of #26298.

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) status: duplicate A duplicate of another issue type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants