Hi guys. I was trying to parse a request from a post method using ContentNegotiation feature with GSON and it’s not working… Ktor produces
UnsupportedMediaTypeException
when try to parse the body. Do you know what i’m doing wrong? I just followed the documentation:
<https://ktor.io/servers/calls/requests.html#typed-objects>
fun main() {
embeddedServer(Netty, port = 8080, watchPaths = listOf(""), module = Application::module).start()
}
fun Application.module() {
install(StatusPages) {
exception<Throwable> {
call.respondText(it.localizedMessage, ContentType.Text.Plain, HttpStatusCode.InternalServerError)
}
}
install(ContentNegotiation) {
gson()
}
routing {
get("/") {
call.respondText("Hello World", ContentType.Text.Html)
}
post("/verify") {
val request = call.receive<Request>()
call.respond(request)
}
}
}
data class Request(val userId: String, val productId: String)
data class Response(val status: String)