Affects: Spring 6.0.0-M6
Spring version: 6.0.0-M6
https://github.com/spring-projects/spring-framework/blob/ba0a835880581244f39e299b624c8a200cfbdf8a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java#L189
In the above line, if the targetType
is resolved as ResolvableType.EmptyType.INSTANCE
, kotilnx serializer fails to serialize it since KotlinSerializationJsonHttpMessageConverter
tries to find serializer of this instance of Type
by using SerializerKt.serializersOrNull
which does not support instance of Type
like below.
https://github.com/spring-projects/spring-framework/blob/877a3d362b6e619a09eb48a8588857b3f75b09a5/spring-web/src/main/java/org/springframework/http/converter/json/KotlinSerializationJsonHttpMessageConverter.java#L176
As a result of this, it encounters below error
java.lang.IllegalArgumentException: typeToken should be an instance of Class<?>, GenericArray, ParametrizedType or WildcardType, but actual type is org.springframework.core.ResolvableType$EmptyType@20eaf254 class org.springframework.core.ResolvableType$EmptyType
at kotlinx.serialization.SerializersKt__SerializersJvmKt.serializerByJavaTypeImpl$SerializersKt__SerializersJvmKt(SerializersJvm.kt:127) ~[kotlinx-serialization-core-jvm-1.4.0.jar:1.4.0]
at kotlinx.serialization.SerializersKt__SerializersJvmKt.serializerOrNull(SerializersJvm.kt:76) ~[kotlinx-serialization-core-jvm-1.4.0.jar:1.4.0]
at kotlinx.serialization.SerializersKt.serializerOrNull(Unknown Source) ~[kotlinx-serialization-core-jvm-1.4.0.jar:1.4.0]
at kotlinx.serialization.SerializersKt__SerializersJvmKt.serializerOrNull(SerializersJvm.kt:43) ~[kotlinx-serialization-core-jvm-1.4.0.jar:1.4.0]
at kotlinx.serialization.SerializersKt.serializerOrNull(Unknown Source) ~[kotlinx-serialization-core-jvm-1.4.0.jar:1.4.0]
at org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter.serializer(KotlinSerializationJsonHttpMessageConverter.java:176) ~[spring-web-6.0.0-M6.jar:6.0.0-M6]
at org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter.canWrite(KotlinSerializationJsonHttpMessageConverter.java:99) ~[spring-web-6.0.0-M6.jar:6.0.0-M6]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:286) ~[spring-webmvc-6.0.0-M6.jar:6.0.0-M6]
at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:238) ~[spring-webmvc-6.0.0-M6.jar:6.0.0-M6]
Comment From: bellatoris
duplicated with https://github.com/spring-projects/spring-framework/issues/29192