<@U8F19U0TD>, the type at line 26 is java.util.Lis...
# announcements
d
@araqnid, the type at line 26 is java.util.List<? extends T>
a
that means it doesn't contain the actual Foo type so it won't deserialize properly then, I suppose
odd, looks like you're doing just what the Jackson module does to get a TypeReference there
you can cheat a bit like this though:
Copy code
inline fun <reified T : Any> listTypeToken(): TypeToken<List<T>> = TypeToken.getParameterized(List::class.java, T::class.java) as TypeToken<List<T>>

inline fun <reified T : Any> listToJsonString(list: List<T>?): String? {
    val listType = listTypeToken<T>().type
    println("generic listType=$listType")
    return Gson().toJson(list, listType)
}

inline fun <reified T : Any> jsonStringToList(json: String?): List<T>? {
    val listType = listTypeToken<T>().type
    println("generic listType=$listType")
    return Gson().fromJson(json, listType)
}

fun fooListToJsonString(list: List<Foo>?): String? {
    val listType = listTypeToken<Foo>().type
    return Gson().toJson(list, listType)
}

fun jsonStringToFooList(json: String?): List<Foo>? {
    val listType = listTypeToken<Foo>().type
    return Gson().fromJson(json, listType)
}