-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Description
While Kotlin Serialization can be used for controllers, it doesn't work to serialize DTOs returned from Actuator @Endpoint
s.
When setting spring.http.converters.preferred-json-mapper=gson
(or jsonb), Gson is used for controllers and actuator endpoints.
When setting spring.http.converters.preferred-json-mapper=kotlin-serialization
, Kotlin Serialization is used for controllers, but Jackson is used for actuator endpoints.
This demo project (sorry that it's in Kotlin, but Kotlin Serialization only works with Kotlin types) demonstrates the issue.
I did a bit of debugging: A breakpoint in org.springframework.http.converter.AbstractKotlinSerializationHttpMessageConverter#canWrite
reveals:
In the WebMVC case:
type
iscom.example.kotlin_serialization.MyDto
clazz
isclass com.example.kotlin_serialization.MyDto
In the actuator case:
type
isjava.lang.Object
clazz
isclass com.example.kotlin_serialization.MyDto
And Spring Framework uses type
to see if there's a generated serializer for the type (the serializers are generated by a compiler plugin, see build.gradle
).