Stephan Schroeder
02/12/2022, 8:54 PMfun main() {
embeddedServer(Netty, port = 8080, host = "localhost") {
configureRouting()
configureSerialization()
}.start(wait = true)
}
fun Application.configureSerialization() {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
})
}
}
fun Application.configureRouting() {
routing {
get("/") {
call.respondText("Wolt Opening Times Formatter")
}
post("/") {
val data = call.receive<String>()
call.respondText(data.toString())
}
}
}
so the GET works and POSTing a String works as well, but as soon as I try to parse into something more ambicious, this fails, e.g. let's update the POST like this
post("/") {
val data = call.receive<TestData>()
call.respondText(data.toString())
}
}
}
@kotlinx.serialization.Serializable
data class TestData(
val monday: Int,
)
then sending over this json
{
"monday": 12
}
fails with
Cannot transform this request's content to simonvoid.gmx.de.time_formatter.plugins.TestData
io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to simonvoid.gmx.de.time_formatter.plugins.TestData`
...
Caused by: io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to simonvoid.gmx.de.time_formatter.plugins.TestData
it's the same exception when I try to receive into a Map (val data = call.receive<Map<String,Int>>()
).
Caused by: io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to kotlin.collections.Map<kotlin.String, kotlin.Int>
Aleksei Tirman [JB]
02/14/2022, 9:05 AMStephan Schroeder
02/15/2022, 10:32 AM