S.
02/02/2022, 2:38 PMFail to serialize body. Content has type: class .models.NewWord, but OutgoingContent expected.
java.lang.IllegalStateException: Fail to serialize body. Content has type: class .models.NewWord, but OutgoingContent expected.
If you expect serialized body, please check that you have installed the corresponding plugin(like `ContentNegotiation`) and set `Content-Type` header.
My test according to the docs (2.0.0 btw) :
testApplication {
val c = createClient {
install(ContentNegotiation) {
json()
}
}
val r = c.post("/word") {
contentType(ContentType.Application.Json)
setBody(NewWord("a", "b", "c"))
}
}
I also tried header() instead of contentType() but doesn't work either
header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
the NewWord class is Serializable ofc. what am I missing?Rustam Siniukov
02/02/2022, 2:43 PMContentNegotiation
from io.ktor.client.plugins
?S.
02/02/2022, 2:50 PMio.ktor.client.plugins.*
I mean, I have this importS.
02/02/2022, 2:50 PMRustam Siniukov
02/02/2022, 2:52 PMContentNegotiation
plugins, for server and for client. It’s possible that you use one for server. The code will still compile, because there is install
in the scope of testApplication
tooS.
02/02/2022, 2:54 PMS.
02/02/2022, 2:54 PMio.ktor:ktor-client-content-negotiation
dependencyRustam Siniukov
02/02/2022, 2:57 PM@DslMarker
to these builders. Thanks for your reportAleksei Tirman [JB]
02/02/2022, 4:11 PM