I have several json models which represent same logic model. e.g:
{"title":"title1","years":"31"}
and {"name":"title1","age":31}
at the moment I make 2 different classes which implement same interface
public class NameModel implements Person {
@SerializedName("name") private String name;
@SerializedName("age") private int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
public class TitleModel implements Person {
@SerializedName("title") private String title;
@SerializedName("years") private int years;
public String getName() {
return title;
}
public int getAge() {
return years;
}
}
public interface Person {
String getName();
int getAge();
}
Is this a correct approach to unify different models to one if they are essentially same, but with different field names?