-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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 Messaging batch payload incompatible with Kotlin #29963
Comments
I think Kotlin lists are expected to be Could you please provide a reproducer? |
I will try to put a full reproducer once I get some time. Meanwhile this workaround fixed it for me: When using Kotlin's default List like: |
I would be really interested by a repro to understand what happens here. When using Kotlin |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Digging further, I saw the root cause is actually in: https://github.com/spring-projects/spring-kafka/blob/main/spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java#L682 with Kotlin the paramType resolves to: while for java, it is: The rest of the code flow in that method ends up assigning the payload content based on the test for paramType and ends up behaving differently for kotlin. I have a working code to reproduce the issue given a local kafka running on port 9092: |
Thanks for digging into that. Indeed as discusses in #22313, Kotlin lists involve declaration site-variance so extra care should be taken for this use case. The related code seems to be on Spring Kafka side so please open a related issue on https://github.com/spring-projects/spring-kafka/issues. cc @garyrussell |
When using batched messaging with Kafka, if the message listener is using Kotlin
List<Message<*>>
in the listener, the ClassUtils.isAssignable is checking if the method is "compatible" with java.util.List and does not work with kotlin's default List:org.springframework.messaging.handler.annotation.support.PayloadMethodArgumentResolver.resolveArgument
Kotlin by default uses List from kotlin.collections and the reflection test are not assignable.
Expected to have it work with kotlin's collection identical to the Java version.
The text was updated successfully, but these errors were encountered: