Is it always necessary to install the `ContentNego...
# ktor
d
Is it always necessary to install the
ContentNegotiation
feature in the server to receive & send serialized (JSON encoded) objects? If the expected, exact content type is specified on both server and receiver, I don't see why
ContentNegotiation
needs to be a hard requirement - I thought this was only about dynamically negotiating a variable content & type at run-time?
d
It's not necessary. You can do this for example without installing the feature:
Copy code
get("/") {
                call.respond(TextContent("{\"key\": \"value\"}", contentType = ContentType.Application.Json))
            }
And you can test request content type:
Copy code
if (call.request.contentType() == ContentType.Application.Json) {
                    val text = call.receiveText()
                    // deserialize text
                }
The content negotiation feature is also used to install serialization mechanisms, so you can't to call.receive<TYPE>() without it