Skip to content

Kotlinx Serialization doesn't work when using ResponseEntity #35281

@Megamiun

Description

@Megamiun

Spring Boot BOM: 4.0.0-M1
Component: spring-web
Version: 7.0.0-M7 (This worked on 6.2.9, but failed for any Types that contained polymorphism types inside)

It seems that at the moment, the AbstractKotlinSerializationHttpMessageConverter fails to work when I use a ResponseEntity to return a response.

I have taken a picture of the debugger in the scenario, showing that the serializer is null, even though the typeSerializersCache has an Serializer registered under GameSummary.

This seems to happen because the hint given to the serializer method is a ResponseEntity, which has no kotlinx serializer impl, thus causing an error. May also happen with other wrapping types.

Image

Also, as some strange reason, even though it is a KClass, the cache being used is the typeSerializerCache instead of the kTypeSerializerCache. I don't know the details, but this may be a problem too?


The types I declared(simplified):

@Serializable
data class GameSummary(
    val state: GameState
)

enum class GameState {
    LEFT_WON,
    RIGHT_WON,
    TIE,
    ONGOING
}

Metadata

Metadata

Assignees

Labels

theme: kotlinAn issue related to Kotlin supporttype: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions