Is there a good Kotlin example equivalent to this:...
# announcements
z
Is there a good Kotlin example equivalent to this: http://f2prateek.com/2017/04/21/unwrapping-data-with-retrofit-2/ for a generic
Envelope<T>
response body adapter? The converter factory in this example uses the Java wildcard generic (
*
) and I'm not sure how to adapt that to Kotlin
d
Try convert java file to kotlin file. I dont believe there is any complication
z
it uses the
Types
class, which I don't seem to have (on Android), is there an extra dependency I need?
g
I think Types is a helper class from Moshi and code from your example uses it
Gson also has analogue of this function
z
TypeToken
?
val envelopeType = Envelope::class.createType().javaType val parameterized = TypeToken.getParameterized(envelopeType, type)
oh, nope, createType needs a parameter
solved it! Though I'm now having unrelated errors. thanks
val parameterized = TypeToken.getParameterized(Envelope::class.java, type)
g
Yes, correct, TypeToken, just wasnot sure about class name
z
I eventually got it all working, thanks for the help!