title: Android Room: Efficient way to transform json result into db object
body: <h1><strong>Problem</strong></h1>
  
  <p>I have a POJO parsed from an API call which looks like this</p>
  
  <pre><code>public class Article {
  
    public Long id;
  
    @Expose
    @SerializedName("section")
    public String section;
  
    @Expose
    @SerializedName("title")
    public String title;
  
    @Expose
    @SerializedName("topics")
    public List&lt;String&gt; topics;
  
    @Expose
    @SerializedName("media")
    public List&lt;Media&gt; media;
  }
  </code></pre>
  
  <p>For the sake of minimizing redundancy and duplicates, I am looking to create a schema like this</p>
  
  <pre><code>@Entity(foreignKeys = { 
            @ForeignKey(entity = Article.class, parentColumns = "id", childColumns = "articleId"), 
            @ForeignKey(entity = Topic.class, parentColumns = "id", childColumns = "topicId"),
            @ForeignKey(entity = Media.class, parentColumns = "id", childColumns = "mediaId")
  }
  public class Articles {
  
      @PrimaryKey
      public Long articleId; 
  
      @ColumnInfo(name = "topic_id")
      public Long topicId;
  
      @ColumnInfo(name = "media_id")
      public Long mediaId;
  }
  
  @Entity
  public class Article {
      // Left out
  }
  
  @Entity
  public class Media {
      // Left out
  }
  </code></pre>
  
  <p>As you can see, when I call the DAO methods to access the database, I can not just pass in the pojo object directly (unless I am mistaken about this). I believe I need to transform the object to one which matches the database entity model.</p>
  
  <h1><strong>Question</strong></h1>
  
  <p>Does the Android Framework provide a natural way to convert from POJO to the database model object? Is there a way to do this other than manually converting it myself?</p>
  
  <h1><strong>Things I've Tried</strong></h1>
  
  <ul>
  <li>I know that I can implement the conversion inside a method within my DAO interface. But then I would have to create a new object and set all the values manually.</li>
  <li>I initially thought typeconverters would work but they seem to convert individual columns.</li>
  </ul>