I've already seen this question:
Deserializing Generic Types with GSON
but my use case is different, what I need is just convert json to T
, and not List<T>
or similar..
Here is what i need in code:
val type: Type = object : TypeToken<T>() {}.type
and then
Gson().fromJson<T>(json, type)
But it's not working. It returns LinkedHashMap or something like that, but not the class represented by T. When I replace T with actual class type, it works, but with T it's not working. Could someone give me some advice ? Thanks