could the POJO used for Gson reused for the class used with Room

Viewed 4452

when using Gson it has POJO created for parsing/serializing the json data result from the remote service. It may have some Gson's annotation

public class User {
    @SerializedName(“_id”)
    @Expose
    public String id;
    @SerializedName(“_name”)
    @Expose
    public String name;
    @SerializedName(“_lastName”)
    @Expose
    public String lastName;

    @SerializedName(“_age”)
    @Expose
    public Integer age;
}

but for the class using with Room, it may have its own annotation:

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;

@Entity
public class User {
    public @PrimaryKey String id;
    public String name;
    public String lastName;
    public int age;
}

could these two be combined into one with all of the annotation from two libs (if there is annotation clash (hope not), it would have to be resolved with long package names)?

2 Answers
Related