Muh Rahmatullah
02/29/2020, 6:47 PMcall.receive<Foo>()
and the error is
java.lang.UnsupportedOperationException: This function has a reified type parameter and thus can only be inlined at compilation time, not called directly.
this is the post handler:
fun Route.createMovie(movies: MutableList<Movie>) {
post("/movie") {
val id = Random.nextInt(1, 100000)
println("header ${call.request.headers["Content-Type"]}")
if(movies.find { it.id == id.toString() } != null) {
// this is example to modify status code in the response and assign the value to the response wrapper
call.response.status(value = HttpStatusCode.BadRequest)
call.respond(Response(data = null, code = call.response.status()?.value, message = "Movie with $id already exist"))
} else {
val payload = call.receive<Movie>()
println(payload)
movies.add(payload)
call.respond(Response(data = movies, code = 200, message = "OK"))
}
}
}
and my Application
fun Application.module(testing: Boolean = false) {
val movies = initData()
install(ContentNegotiation) {
gson {
setPrettyPrinting()
}
}
routing {
get("/") {
call.respondText("A very simple rest api using k-tor!", contentType = ContentType.Text.Plain)
}
movies(movies)
movieById(movies)
deleteById(movies)
createMovie(movies)
}
}
Also, I already set the Content-type to application/json when sending the request. TIA, any help would be greatcall.receive(Movie::class)
and now it works