I'm new to Ktor, and I'm trying to build a backend that processes login credentials. I'm attempting to use the content negotiation feature to convert JSON into a native Kotlin object, but I keep getting an unsupported media type exception. Here is my code:
fun Application.main() {
    install(CallLogging)
    install(DefaultHeaders)
    install(ContentNegotiation) {
        register(ContentType.Application.Json, GsonConverter())
    }
    routing {
        get("/") {
            call.respondHtml {
                head {
                    title("Kotlin Webapp")
                    script {
                        type = ScriptType.textJScript
                        src = "main.bundle.js"
                    }
                }
                body {
                    div {
                        id = "root"
                    }
                }
            }
        }
        post("/login") {
            val credentials = call.receive<Credentials>()
            println(credentials)
        }
    }
}
data class Credentials(val username: String, val password: String)
And here is the incoming Json I am trying to convert, which I am sending via XMLHttpRequest:
{"username":"Jamdan2","password":"sometext"}
I have searched the web for answers, but could not find what I am doing wrong. Can anybody help?
 
    