I have a POJO parsed from an API call which looks like this
public class Article {
public Long id;
@Expose
@Serialized
You can use @Embedded annotation for your related POJO which refers to another class.
You can do like this:
Article.java
@Entity(tableName = "Article")
public class Article {
@ColumnInfo (name = "article_id")
public Long id;
@Expose
@SerializedName("section")
public String section;
@Expose
@SerializedName("title")
public String title;
@Expose
@SerializedName("topics")
public List topics;
@Embedded // We need relation to Media table
@Expose
@SerializedName("media")
public List media;
}
Media.java
public class Media {
@ColumnInfo (name = "media_id")
public Long id;
}
So now on, you can directly use this POJO as Entity for ROOM.
Please note:
Though i'm not sure about how you'll handle that relation (because, Media obj is in list for Article class, you'll need to use type converter for that)
Reference from here