How to use TypeToken + generics with Gson in Kotlin
Create this inline fun: inline fun <reified T> Gson.fromJson(json: String) = fromJson<T>(json, object: TypeToken<T>() {}.type) and then you can call it in this way: val turns = Gson().fromJson<Turns>(pref.turns) // or val turns: Turns = Gson().fromJson(pref.turns) Previous Alternatives: ALTERNATIVE 1: val turnsType = object : TypeToken<List<Turns>>() {}.type val turns = Gson().fromJson<List<Turns>>(pref.turns, turnsType) You have to put … Read more