Matti MK
12/29/2022, 2:16 PMContent-Type text/html; charset=UTF-8
. The response is as follows { "result": [ "foo", "bar" ] }
. When I try to serialize this into a POJO Ktor I get the following error:
No transformation found: class io.ktor.utils.io.ByteBufferChannel -> class FooList
This is most certainly about the wrong Content-Type
, as with valid application/json
header everything works as expected. Unfortunately, I cannot change the server’s headers.
Is there a workaround for this on client side? I tried with accept(ContentType.Text.Plain)
as well as accept(ContentType.Any)
but those don’t really help.Matti MK
12/29/2022, 2:22 PMMatti MK
12/29/2022, 2:50 PMJson.decodeFromString<FooClass>(response.body())
Rustam Siniukov
12/29/2022, 3:08 PMContentNegotiation
plugin
install(ContentNegotiation) {
register(ContentType.Text.Plain, KotlinxSerializationConverter(Json))
}
Matti MK
12/29/2022, 3:10 PMJson
as a `SerialFormat`:
https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-serial-format/Matti MK
12/29/2022, 3:15 PMval format = Json {
prettyPrint = true
encodeDefaults = true
}
register(ContentType.Text.Plain, KotlinxSerializationConverter(format))
Yet the issue still persists. I would be surprised if there wasn’t something off with the format here.
Do you know if there’s docs available for this?Rustam Siniukov
12/29/2022, 3:16 PMContent-Type
header?Matti MK
12/29/2022, 3:17 PMContent-Type text/html; charset=UTF-8
Rustam Siniukov
12/29/2022, 3:18 PMContentType.Text.Html
Matti MK
12/29/2022, 3:23 PM