Ktor JSON 解析 Post 请求无效

Ktor JSON Parsing on Post Request is not working

每次我从 post 人发送 post 请求并且服务器给出此错误,即使我检查我是否收到 Content-Type = Application/ JSON。但是还是报这个错。

原因:java.lang.NoSuchMethodError:java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer;

这是我的文件

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
)

所以我通过将项目 SDK 1.8 更改为 11 解决了这个问题。

ktor_version:1.6.7 已解决此问题。