Ktor JSON Parsing on Post Request is not working

Viewed 454

Every time I send a post request from the postman and the server gives this error, even I checked if I'm receiving Content-Type = Application/ JSON. But still giving this error.

Caused by: java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer;

Here are my files

Application File:

fun main() {
    embeddedServer(Netty, port = 8080, host = "192.168.0.109") {
        install(ContentNegotiation){
            json()
        }
        configureRouting()
    }.start(wait = true)
}

Request:

post("/login") {

    val userInfo = call.receive<UserInfo>()
    println(userInfo)

    call.respondText("Everything is working fine")
}

Model Class:

@Serializable
data class UserInfo(
    val email: String,
    val password: String
)
2 Answers

So I Solved This Issue by Changing Project SDK 1.8 to 11.

enter image description here

ktor_version:1.6.7 has fixed this problem.

Related