nfrankel
09/18/2017, 1:42 PMtrubesv
09/18/2017, 1:48 PMinline fun <reified T> getList(json: String): T? = Gson().fromJson<T>(json, object : TypeToken<T>() {}.type)
(used to deserialize an ArrayList of custom objects)kevinmost
09/18/2017, 1:50 PMgetList
the name you want for that method? val user = getList<User>(json)
doesn't seem right to metrubesv
09/18/2017, 1:54 PMfun newList() { /* create & populate a new list */ }
fun someFunction(list: ArrayList<SomeObject>) { ... }
someFunction(getList(json) ?: newList())
I don't clearly understand exactly why but I don't need to specify <ArrayList<SomeObject>>
before the parenthesis somehowGson()
"error", I must have kept it after trying things and forgot to change it 🙂diesieben07
09/18/2017, 3:15 PMtrubesv
09/18/2017, 4:24 PMdiesieben07
09/18/2017, 7:27 PMtrubesv
09/18/2017, 9:24 PMarthur
09/18/2017, 10:20 PMtrubesv
09/18/2017, 10:24 PMinline fun <reified T> Gson.getList(json: String): T? = fromJson<T>(json, object : TypeToken<T>() {}.type)
kirillrakhman
09/19/2017, 11:39 AMtrubesv
09/19/2017, 2:27 PMdiesieben07
09/19/2017, 2:40 PMtrubesv
09/19/2017, 3:02 PMTypeToken
, my guess is that I should val
it but does it work outside a class
?diesieben07
09/19/2017, 3:03 PMTypeToken
, since you don't have anything to cache by (i.e. you don't have a key for the cache).trubesv
09/19/2017, 3:23 PM