https://kotlinlang.org logo
#android
Title
# android
d

dawidhyzy

09/18/2017, 6:33 AM
This is normal. Same applies to Gson
i

indyfromoz

09/18/2017, 7:31 AM
Do you have a sample that works with Gson?
d

dawidhyzy

09/18/2017, 7:35 AM
Sample? No. But it works the same. Also same as in Java.
i

indyfromoz

09/18/2017, 7:53 AM
🤔
k

kyle

09/18/2017, 8:11 PM
if you want it to work with proguard and obfuscation turned on then you need to either use the
@SerializedName
annotation in gson or
@JsonName
in moshi
i

indyfromoz

09/18/2017, 9:45 PM
Here is one of the model classes I am using -
Copy code
data class Token (
        @Json(name = "client_id") val clientId: String,
        @Json(name = "issued_at") val issuedAt: String,
        @Json(name = "access_token") val accessToken: String,
        @Json(name = "expires_in") val expiresIn: String
)
Without the following in Proguard -
Copy code
-keepclassmembers class com.lianasolutions.progit.models.** {
  <init>(...);
  <fields>;
}

-dontwarn org.jetbrains.annotations.**
-keep class kotlin.Metadata { *; }
the app fails to run with an exception. All of it is discussed in https://github.com/square/moshi/issues/345
I was not raising an issue with
moshi-kotlin
, just sharing what I found while using
moshi
and
moshi-kotlin
d

dawidhyzy

09/19/2017, 5:42 AM
that’s normal add Proguard rules
It’s not Kotlin specific
i

indyfromoz

09/19/2017, 7:59 AM
Have you actually read the issue? It is specific to
moshi-kotlin
and Proguard.
🙄