I've a problem using Fuel's responseObject
in a generic fashion. I'm trying to develop a centralized method with components getting their HTTP response object already deserialized, ready to go. It looks like this:
class Controller(private val url: String) {
fun <T> call(endpoint: String): T {
return "$url/$endpoint".httpGet().responseObject<T>()
}
}
class App(private val controller: Controller) {
fun getModel() {
val model = controller.call<AppModel>("model")
// use model
}
}
Of course, Controller.call
would handle errors, and add common request parameters. The deserialization from JSON is supposed to be handled by Jackson (AppModel
is a simple data class Jackson should pick up automatically), so I'm working with fuel-jackson:1.12.0
as an added dependency.
Now, using Kotlin-1.2.21, I get this compiler error:
Error:(35, 97) Kotlin: Cannot use 'T' as reified type parameter. Use a class instead.
How do I work around this, perhaps by switching to a different Fuel method?
I've considered making call
inline (to reify T), but this defeats the purpose of having a private val url
.