使用混淆器进行改造不会反序列化某些模型

Retrofit with proguard is not deserializing some models

在我的代码中 User 尽管服务器返回了模型,但模型并未被反序列化。从我的代码 client.getPerson() returns Person 对象的实例但是 client.getUser() returns 一个空字符串 可能是什么问题?

我的Clientclass如下,

public class Client implements Serializable {

@SerializedName("address")
private String address;

@SerializedName("nhif_no")
private String nhifNo;

@SerializedName("occupation_name")
private String occupationName;

@SerializedName("person")
private Person person;

@SerializedName("kra_pin")
private String kraPin;

@SerializedName("user")
private User user;

@SerializedName("client_id")
private int clientId;

@SerializedName("sales_agent_id")
private int salesAgentId;

public void setAddress(String address){
    this.address = address;
}

public String getAddress(){
    return address;
}

public void setNhifNo(String nhifNo){
    this.nhifNo = nhifNo;
}

public String getNhifNo(){
    return nhifNo;
}

public void setOccupationName(String occupationName){
    this.occupationName = occupationName;
}

public String getOccupationName(){
    return occupationName;
}

public void setPerson(Person person){
    this.person = person;
}

public Person getPerson(){
    return person;
}

public void setKraPin(String kraPin){
    this.kraPin = kraPin;
}

public String getKraPin(){
    return kraPin;
}

public void setUser(User user){
    this.user = user;
}

public User getUser(){
    return user;
}

public void setClientId(int clientId){
    this.clientId = clientId;
}

public int getClientId(){
    return clientId;
}

public void setSalesAgentId(int salesAgentId){
    this.salesAgentId = salesAgentId;
}

public int getSalesAgentId(){
    return salesAgentId;
}
}

我的Personclass如下,

public class Person implements Serializable {

@SerializedName("last_name")
private String lastName;

@SerializedName("middle_name")
private String middleName;

@SerializedName("first_name")
private String firstName;

@SerializedName("person_id")
private int personId;

public void setLastName(String lastName){
    this.lastName = lastName;
}

public String getLastName(){
    return lastName;
}

public void setMiddleName(String middleName){
    this.middleName = middleName;
}

public String getMiddleName(){
    return middleName;
}

public void setFirstName(String firstName){
    this.firstName = firstName;
}

public String getFirstName(){
    return firstName;
}

public void setPersonId(int personId){
    this.personId = personId;
}

public int getPersonId(){
    return personId;
}
}

我的Userclass如下,

public class User implements Serializable{

@SerializedName("role_id")
private int roleId;

@SerializedName("email")
private String email;

public void setRoleId(int roleId){
    this.roleId = roleId;
}

public int getRoleId(){
    return roleId;
}

public void setEmail(String email){
    this.email = email;
}

public String getEmail(){
    return email;
}
}

我的JSON文件如下, { "client": { "client_id": 128, "nhif_no": "KJNH1289", "kra_pin": "210986", "sales_agent_id": 43, "address": "Kikuyu", "occupation_name": "Prisoner", "person": { "person_id": 358, "first_name": "Kamiti", "middle_name": "Jela", "last_name": "Baridi", "gender": { "gender_id": 1, "name": "Male" } }, "user": { "email": "jelabaridi@gmail.com", "role_id": 2 } } }

通过在 proguard 规则文件中添加以下行来修复它

-keep class org.myapp.mypackage.models.** { *; }