title: Consuming restapi and store Json response to different tables in Springboot JPA?
body: <p>I am new to Spring boot and these JSON objects. I have a requirement where I need to invoke GET RestAPI and it returns list of nested Json Objects. I need some particular fields from Json object and store it into Database(SQL Server-backend) tables.
  And these tables having relationship between them,also my Entity class and these Json structure not same. below is my code,
  Json response:</p>
  <pre><code>[
    {
      &quot;ApplicationName&quot;: &quot;ACD tool&quot;,
      &quot;city&quot;: &quot;Europe&quot;,
      &quot;IsActive&quot;: &quot;true&quot;,
      &quot;AppOwner&quot;: &quot;Ragavendr raj&quot;,
      &quot;AppTeamMember&quot;: &quot;Siyan&quot;,
      &quot;CreatedBy&quot;: &quot;pav&quot;,
      &quot;AppDetails&quot;: {
        &quot;Language&quot;: &quot;VB.net&quot;,
        &quot;Version&quot;: &quot;2.0&quot;
      }
    },
    {
      &quot;ApplicationName&quot;: &quot;QR check&quot;,
      &quot;city&quot;: &quot;US&quot;,
      &quot;IsActive&quot;: &quot;true&quot;,
      &quot;AppOwner&quot;: &quot;Amar&quot;,
      &quot;AppTeamMember&quot;: &quot;miyas&quot;,
      &quot;CreatedBy&quot;: &quot;rosh&quot;,
      &quot;AppDetails&quot;: {
        &quot;Language&quot;: &quot;c#&quot;,
        &quot;Version&quot;: &quot;2.0&quot;
      }
    }
  ]
  </code></pre>
  <p>Table entities:
  Application Entity:</p>
  <pre><code>    @Entity
  @Table(name=&quot;APPLICATION&quot;)
  public class Application implements Serializable {
      private static final long serialVersionUID = 1L;
      
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name=&quot;APPLICATION_ID&quot;)
      private long applicatioId;
      
      @Column(name=&quot;APPLICATION_NAME&quot;)
      private String applicationName;
      
      @ManyToMany(mappedBy=&quot;application&quot;)
      private List&lt;ApplicationUserRoleMap&gt; applicationUserRoleMap;
      
      @Column(name=&quot;CREATED_BY&quot;)
      private String createdBy;
      
      @Column(name=&quot;CREATED_ON&quot;)
      private String createdOn;
      
      @Column(name=&quot;MODIFIED_BY&quot;)
      private String modifiedBy;
      
      @Column(name=&quot;MODIFIED_ON&quot;)
      private String modifiedOn;
      
      @Column(name=&quot;DELETE_FLG&quot;)
      private String deleteFlg;
      
      @Column(name=&quot;DISPLAY_FLG&quot;)
      private String displayFlg;
      
      //getters and setters
  
  
  }
  </code></pre>
  <p>User Entity:</p>
  <pre><code>    @Entity
  @Table(name=&quot;USER&quot;)
  public class User implements Serializable {
      private static final long serialVersionUID = 1L;
      
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name=&quot;USER_ID&quot;)
      private long userId;
      
      @Column(name=&quot;USER_NAME&quot;)
      private String userName;
      
      @ManyToMany(mappedBy=&quot;user&quot;)
      private List&lt;ApplicationUserRoleMap&gt; applicationUserRoleMap;
  
      @Column(name=&quot;CREATED_BY&quot;)
      private String createdBy;
      
      @Column(name=&quot;CREATED_ON&quot;)
      private String createdOn;
      
      @Column(name=&quot;MODIFIED_BY&quot;)
      private String modifiedBy;
      
      @Column(name=&quot;MODIFIED_ON&quot;)
      private String modifiedOn;
      
      @Column(name=&quot;DELETE_FLG&quot;)
      private String deleteFlg;
      
      @Column(name=&quot;DISPLAY_FLG&quot;)
      private String displayFlg;
      
      //getters and setters
      
      
  }
  </code></pre>
  <p>Role Entity:</p>
  <pre><code>   @Entity
  @Table(name=&quot;ROLE&quot;)
  public class Role implements Serializable {
      private static final long serialVersionUID = 1L;
      
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name=&quot;ROLE_ID&quot;)
      private long roleId;
      
      @Column(name=&quot;ROLE_NAME&quot;)
      private String roleName;
      
      @ManyToMany(mappedBy=&quot;role&quot;)
      private List&lt;ApplicationUserRoleMap&gt; applicationUserRoleMap;
  
      @Column(name=&quot;CREATED_BY&quot;)
      private String createdBy;
      
      @Column(name=&quot;CREATED_ON&quot;)
      private String createdOn;
      
      @Column(name=&quot;MODIFIED_BY&quot;)
      private String modifiedBy;
      
      @Column(name=&quot;MODIFIED_ON&quot;)
      private String modifiedOn;
      
      @Column(name=&quot;DELETE_FLG&quot;)
      private String deleteFlg;
      
      @Column(name=&quot;DISPLAY_FLG&quot;)
      private String displayFlg;
      
      //getters and setters
  }
  </code></pre>
  <p>ApplicationUserRoleMap entity:</p>
  <pre><code>@Entity
  @Table(name=&quot;APPLICATION_USER_ROLE_MAP&quot;)
  public class ApplicationUserRoleMap implements Serializable {
      private static final long serialVersionUID = 1L;
      
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      @Column(name=&quot;APPLICATION_USER_ROLE_MAP_ID&quot;)
      private long applicatioUserRoleMapId;
      
      @ManyToMany
      @JoinColumn(name=&quot;APPLICATION_ID&quot;)
      private List&lt;Application&gt; application;
      
      @ManyToMany
      @JoinColumn(name=&quot;USER_ID&quot;)
      private List&lt;User&gt; user;
      
      @ManyToMany
      @JoinColumn(name=&quot;ROLE_ID&quot;)
      private List&lt;Role&gt; role;
  
      @Column(name=&quot;CREATED_BY&quot;)
      private String createdBy;
      
      @Column(name=&quot;CREATED_ON&quot;)
      private String createdOn;
      
      @Column(name=&quot;MODIFIED_BY&quot;)
      private String modifiedBy;
      
      @Column(name=&quot;MODIFIED_ON&quot;)
      private String modifiedOn;
      
      @Column(name=&quot;DELETE_FLG&quot;)
      private String deleteFlg;
      
      @Column(name=&quot;DISPLAY_FLG&quot;)
      private String displayFlg;
      
      //getters and setters
      
  
  }
  </code></pre>
  <p>From json object fields AppOwner and AppTeamMember should added to roles table and their corresponding name added to user table, role-user-appliication ids mapping added to map table.</p>
  <p>Can someone suggest me the best way to achieve this...Thanks</p>