-
Notifications
You must be signed in to change notification settings - Fork 38.5k
KotlinSerializationJsonHttpMessageConverter doesn't work on MutableList #33528
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
Comments
That's due to the combination of a On Spring side, to handle this use case I recommend switching from fun main(args: Array<String>) {
val client = RestClient.builder().messageConverters {
it.clear() // I will likely add the capability to provide directly a list of converters to avoid that inefficient default init + clear
it.add(StringHttpMessageConverter())
it.add(KotlinSerializationJsonHttpMessageConverter())
}.build()
val data = mutableListOf<String>()
data.add("1")
data.add("2")
println(client.post().uri("https://httpbin.org/post")
.bodyWithType<List<String>>(data).contentType(MediaType.APPLICATION_JSON)
.retrieve().body<String>())
} Alternatively if you really need to stay with |
See #33536 for the improved message converters initialization. |
Thanks @sdeleuze |
I am unsure as well, there may be some compile-time type parameter detection done by the Kotlin compiler in |
Feedback from Kotlin team
That confirms we can't do better than current behavior for that use case. |
Affects: 6.1.12
Hi all,
I'm using spring-web in Kotlin as a REST client and I encountered some issues when trying to serialize a MutableList
I prepared a sample code to show the issue:
But when I run this code, I get this error:
No HttpMessageConverter for java.util.ArrayList and content type "application/json"
I assumed
KotlinSerializationJsonHttpMessageConverter
Would be able to convert this to["1", "2"]
, but it doesn't seem to workThe text was updated successfully, but these errors were encountered: