Skip to content

KotlinSerializationJsonHttpMessageConverter doesn't work on MutableList #33528

@ChananM

Description

@ChananM

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:

fun main() {
    val client = RestTemplate(listOf(
        KotlinSerializationJsonHttpMessageConverter()
    ))
    val data = mutableListOf<String>()
    data.add("1")
    data.add("2")
    val entity = HttpEntity(data, HttpHeaders().apply {
        contentType = MediaType.APPLICATION_JSON
    })
    val response = client.exchange("https://httpbin.org/post", HttpMethod.POST, entity, String::class.java)
    logger.info(response.body)
}

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 work

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently applytheme: kotlinAn issue related to Kotlin support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions