kenkousen
06/28/2020, 7:53 PMGson().fromJson(json, MyDataClass::class.java)
and I realize I could write
inline fun <reified T> Gson.fromJson(json: String): T = this.fromJson(json, T::class.java)
That way I can reduce the above expression to
Gson().fromJson<MyDataClass>(json)
My question is, is it worth doing that? Do I really gain anything? What do you think?jw
06/28/2020, 7:57 PMtypeOf
or else things like List and Map and other generic types will be broken.kenkousen
06/28/2020, 8:05 PMtypeOf<T>.javaClass
works, but the question is, should I be trying that at all? Should I just go with the two-arg version that takes a Java class, or is it worth it to try to add the extension function?andylamax
06/28/2020, 8:19 PMkenkousen
06/28/2020, 8:19 PMfromJson(json, typeOf<T>().javaType)
and now I get a NotImplementedError
(Java type is not yet supported for types created with createType) pointing to my data class, which I don't understand yet, but I'm still not sure this is a good idea in the first placekenkousen
06/28/2020, 8:20 PM