Gson in Release works differently than in Debug on Android

-1

I find that an app where I load data from json with library gson to a custom object list, in realease does not fill the list. What is due?

This is my object:

public class Route {

    private String title;

    public void setTitle(String title) {
        this.title = title;

    }

    public String getTitle() {
        return this.title;
    }
}
    
asked by Webserveis 22.11.2016 в 18:02
source

1 answer

3

This response SO say that if the release directive is assigned in the version minifyEnabled

release {
    minifyEnabled true
}

The compiler will obfuscate the names of the variables so that they occupy less space so that in the object the reference of the field must be specified so that gson can enter the data automatically.

  

@SerializedName ("json_field_name")

Example:

public class Route {
    @SerializedName("title")
    private String title;

    public void setTitle(String title) {
        this.title = title;

    }

    public String getTitle() {
        return this.title;
    }
}
    
answered by 22.11.2016 / 20:33
source