César
03/30/2022, 12:46 PMval courses: Collection<Course> = gson.fromJson(response.string(), Collection<Course>::class.java)
(the Collection<Course>::class.java
part)César
03/30/2022, 12:57 PMval listOfMyClassObject: Type = object : TypeToken<Collection<Course>>() {}.type
val courses: Collection<Course> = gson.fromJson(response.string(), listOfMyClassObject)
but TypeToken
is a class from Gson so I'm still curious how it can be done without thatPaul Griffith
03/30/2022, 2:35 PMinline fun <reified T> Gson.fromJson(json: String): T {
return fromJson(json, T::class.java)
}
would be, in use, gson.fromJson<Collection<Course>>(response.string())
also, obligatory: don’t use GSON 🙂César
03/30/2022, 2:38 PMPaul Griffith
03/30/2022, 3:07 PMkotlinx-serialization
but because it’s compile-time generation of code (to be multiplatform) it makes some tradeoffs that can make it more awkward to use for certain thingsCésar
03/30/2022, 3:30 PMKlitos Kyriacou
03/31/2022, 9:12 AM