Please note that some might suggest i add the model class to the proguard -keep, i emphasize that i don't want to do that, due to security restriction guidelines imposed by my employer, i'm looking for a solution that doesn't involve editing proguard rules
Using Gson to parse the a Json formatted string into an array mapped to a Pojo, everything works fine is debug variant but when in release build with proguard enabled, the properties of the mapped Pojo objects return null causing the application to crash, below is the model/pojo class:
package com.xx.xxxxxxx
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
public class BeneficiaryModel implements Serializable {
@SerializedName("beneficiaryId")
@Expose
private String beneficiaryId;
@SerializedName("beneficiaryName")
@Expose
private String beneficiaryName;
@SerializedName("beneficiaryType")
@Expose
private String beneficiaryType;
@SerializedName("status")
@Expose
private String status;
public String getBeneficiaryId() {
return beneficiaryId;
}
public void setBeneficiaryId(String beneficiaryId) {
this.beneficiaryId = beneficiaryId;
}
public String getBeneficiaryName() {
return beneficiaryName;
}
public void setBeneficiaryName(String beneficiaryName) {
this.beneficiaryName = beneficiaryName;
}
public String getBeneficiaryType() {
return beneficiaryType;
}
public void setBeneficiaryType(String beneficiaryType) {
this.beneficiaryType = beneficiaryType;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
and this is how i serilaize the json string to array of objects
Gson gson = new Gson();
clientes = gson.fromJson(beneficiaryStringJsonArray, BeneficiaryModel[].class);
models = new ArrayList<BeneficiaryModel>(Arrays.asList(clientes));
Log.e("TAG", models.get(0).getBeneficiaryId() + "," + models.get(0).getBeneficiaryName());
// Log returns null , null
Here's the portion of the Json string response needs to be serialized:
[{"beneficiaryId":"XYZ54646464646","beneficiaryName":"xxxxxxxxxxxxxx1","beneficiaryType":"","status":"ACTIVE"},{"beneficiaryId":"XYZ5468524654","beneficiaryName":"xxxxxxxxxxxxx2","beneficiaryType":"","status":"ACTIVE"}]
( as i mentioned before everything works fine in debug mode )