【发布时间】:2021-03-09 00:25:47
【问题描述】:
webSocket("/ws") {
try {
while (true) {
when(val frame = incoming.receive()){
is Frame.Text -> {
val text = frame.readText() //i want to Serialize it to class object
send(Frame.Text(processRequest(text)))
}
else -> TODO()
}
}
} finally {
TODO()
}
}
我想序列化frame.readText() 以返回类对象
我对 Ktor 世界完全陌生,我不知道这是否可能
【问题讨论】:
-
您能否更好地解释一下您的
text变量中有什么?这是一个JSON字符串?或者是其他东西?如果你有一个 JSON 字符串,你可以使用kotlinx.serialization
标签: kotlin ktor kotlinx.serialization