How to Use Common Model Class for Retrofit and Squidb

In my android app, I am reading data from the server in JSON format and storing it local SQLite db.

I am using retrofit and Gson for reading and converting Json into objects.

For e.g.

@Parcel
public class PersonResponse {

    @SerializedName("name")
    public String name;
}

I am using Yahoo Squidb as ORM.

@TableModelSpec(className = "Person", tableName = "people")
public class PersonSpec {

    @ColumnSpec(name="name", defaultValue="")
    public String name;

  public static Person create(PersonResponse obj) {

    return new Person(obj){...};
  }
}

Trouble is I can't use a single object for both. Therefore, it has become pain to maintain two similar pojos.

I have to now convert from PersonResponse to Person

Person p = Person.create(obj_person_response);

Has anyone implemented it. Please suggest.

1
Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article