Hi :slightly_smiling_face: I am running into a typ...
# kotlin-fuel
s
Hi 🙂 I am running into a type issue while implementing a pagination helper: (issue is https://youtrack.jetbrains.com/issue/KT-22798)
Copy code
class User(val id: Int, val name: String, val username: String)
data class Page<T : Any>(val elements: List<T>, val page: Int, val totalPages: Int)

inline fun <reified T : Any> requestSingle(page: Int): Page<T> {
    val (request, response, result) = Fuel
        .get("<https://jsonplaceholder.typicode.com/users>")
        .header(Headers.ACCEPT, "application/json")
        .responseObject<List<T>>()
    return Page(result.get(), page, 3) // simulate 3 pages
}
inline fun <reified T : Any> requestAll(): List<T> {
    val firstPage = requestSingle<T>(1)
    val allElements = firstPage.elements.toMutableList()
    for (i in 2..firstPage.totalPages) allElements += requestSingle<T>(i).elements
    return allElements
}
println(requestAll<User>()) // getting a List<Map<String, Any>> instead of List<User>
Is there a sensible workaround for this with fuel, or do I need to use
resultString
and parse it manually with a manually configured deserializer ?