Hi! I’m configuring Content negotiation for ktor c...
# ktor
a
Hi! I’m configuring Content negotiation for ktor client as follow:
Copy code
install(ContentNegotiation) {
    json(Json {
        prettyPrint = true
        isLenient = true
        ignoreUnknownKeys = true
    }, contentType = ContentType.Application.Json)
}
But client is responding that one incoming param is not on the serialized data class and I should add ignoreUnknownKeys = true to Json{}, but I already have it
a
Can you share the data class and the actual JSON?
a
I’ll share a test
Copy code
@Serializable
data class Test(val singleParam: String, val otherParam: String)

get("/test") {
    <http://call.application.log.info|call.application.log.info>("Test starts")
    <http://call.application.log.info|call.application.log.info>("Test ends")
    call.respond(HttpStatusCode.Accepted, Test("test", "test"))
}
Copy code
@Test
fun eventTest() = myTestApplication {
    val response = client.get("$PATH/test") {
        header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
    }
    Json.decodeFromString<TestModel>(response.bodyAsText())
}
I’m wondering if I need to config content-negotiation on test client
a
What is the definition of the
TestModel
class?
a
Ups…sorry
Copy code
@Serializable
data class TestModel(val singleParam: String)
a
Are you sure you’re not using the global
Json
instance there in your test, which does not have any configuration? What is the error exactly?
a
You should be right
I’ll test again
👍 1
Yes, that was the problem! Many thanks!
🤝 1