Igor Kolomiets
01/02/2022, 4:48 AM@Serializable
data class Age(val value: Int)
@Serializable
data class Update<T>(val old: T, val new: T)
fun main() {
embeddedServer(Netty, port = 8080) {
install(ContentNegotiation) {
json()
}
routing {
update<Age>()
}
}.start(wait = true)
}
inline fun <reified T> Route.update() {
post("/") {
val update = call.receive<Update<T>>()
<http://application.log.info|application.log.info>("XXX update={}", update)
call.respond(HttpStatusCode.OK, "OK")
}
}
Trying
% curl -v -H "Content-Type: application/json" -POST <http://localhost:8080/|http://localhost:8080/> -d '{"old":{"value":1},"new":{"value":2}}'
makes Ktor throw:
java.lang.UnsupportedOperationException: This function has a reified type parameter and thus can only be inlined at compilation time, not called directly.
I found similar issue https://youtrack.jetbrains.com/issue/KTOR-582 that was identified as Kotlin compiler’s issue and eventually resolved as Fixed.
Could this be regression with Kotlin compiler again? If not, can somebody advise how to avoid this exception? My project really needs such generic Route.update()
function.
Thank you!Aleksei Tirman [JB]
01/13/2022, 2:10 PMIgor Kolomiets
01/19/2022, 4:28 PM