kamikat / moshi-jsonapi

JSON API v1.0 Specification in Moshi.
MIT License
156 stars 34 forks source link

Error parsing attributes on minify mode #100

Closed di0n0s closed 5 years ago

di0n0s commented 5 years ago

Hi,

When minify mode is activated (release), Moshi cannot parse attributes. I think because resource objects are obfuscated by ProGuard/R8 but I don't understand why because I think I added all necessary rules recommended on Readme.

Here is one of my Resources:

import com.squareup.moshi.Json;
import moe.banana.jsonapi2.JsonApi;
import moe.banana.jsonapi2.Resource;

@JsonApi(type = "consents")
public class ConsentResponse extends Resource {

    public String version;
    @Json(name = "activation_date")
    public String activationDate;
    public String title;
    public String text;

}

My whole project is in Kotlin but I decided to do resources objets on Java because I had some problems parsing attributes.

Here is my ProGuard/R8 rules:

-keepattributes Signature
-keep class moe.banana.jsonapi2.** {
    *;
}

-keep public class moe.banana.jsonapi2.**

Here is my ResourceAdapterFactory and Retrofit builder:

       val jsonApiAdapterFactory = ResourceAdapterFactory.builder()
            .add(UserResponse::class.java)
            .add(ConsentResponse::class.java)
            // ...
            .build()

        val moshi = Moshi.Builder()
            .add(jsonApiAdapterFactory)
            .build()

        return Retrofit.Builder()
            .baseUrl(BuildConfig.API_ENDPOINT)
            .addConverterFactory(JsonApiConverterFactory.create(moshi))
            .addConverterFactory(GsonConverterFactory.create())
            .client(builder.build())
            .build()
            .create(ApiService::class.java)

Here is my dependencies:

    implementation 'com.squareup.moshi:moshi:1.8.0'
    implementation 'moe.banana:moshi-jsonapi:master-SNAPSHOT'

Does anyone know what I'm doing wrong?

Thank you very much in advance ;)

di0n0s commented 5 years ago

SOLVED:

@Json(name = "") annotation is mandatory in all attributes if you use ProGuard/R8

P.S.: It would be interesting to write this down on Readme ;)