Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit doesn't serialize second object in my response class

My problem is when running my app with release APK (proguard is enabled), GSON doesn't serialize my second object. First object is successfully serialized. But, app runs in debug mode everything is fine.

My app uses Retrofit2.6 and Proguard. Gradle version is gradle:3.5.1

My json data from WebServer

 {
  "error": false,
  "contents": [
    {
      "id": 1,
      "channel": {
        "id": 7,
        "language_id": 1
      },
      "publisher": {
        "id": 1,
        "name": "Name of Publisher"
      },
      "title": "Some title",
      "description": "This is description",
      "subscribed": false
    }
  ]
}

And this is Response class for Retrofit

public class GetContentsResponse{

    @SerializedName("error")
    @Expose
    private boolean mError;

    @SerializedName("contents")
    @Expose
    private List<Content> mContents;

}

public class Content {

    @SerializedName("id")
    @Expose
    private int mId;

    @SerializedName("channel")
    @Expose
    private Channel mChannel;

    @SerializedName("publisher")
    @Expose
    private Publisher mPublisher;

    @SerializedName("title")
    @Expose
    private String mTitle;

    @SerializedName("description")
    @Expose
    private String mDescription;

    @SerializedName("subscribed")
    @Expose
    private boolean mSubscribed;

    public int getId() {
        return mId;
    }

    public Channel getChannel() {
        return mChannel;
    }

    public String getTitle() {
        return mTitle;
    }

    public String getDescription() {
        return mDescription;
    }

    public boolean isSubscribed() {
        return mSubscribed;
    }

    public Publisher getPublisher() {
        return mPublisher;
    }

}

This is my proguard rules

-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn org.codehaus.mojo.animal_sniffer.*
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-keepattributes *Annotation*

Publisher object is parsing when debug mode (proguard disabled). Publisher object is null when Release APK runs (proguard enabled).

I really research this problem very much. But i don't understand what is the problem is? Is there anyone who can help?

Edit: I kept all my model classes in Proguard rules for now but there's a mysterious mistake here. I can't find it. Why Channel object serialized but Publisher object didn't serialize?

like image 254
serkancay Avatar asked Oct 24 '25 16:10

serkancay


1 Answers

Add this in your proguard

-keep public class com.package.name.models.** { *; }

Note:- com.package.name.models - this is your package name where your POJO class is located.

That's it.

like image 137
Bhoomin Naik Avatar answered Oct 27 '25 04:10

Bhoomin Naik