title: copying all properties of one pojo to another in java?
body: <p>I have below POJO of some third party jar which we cannot expose to our clients directly.</p>
  
  <p><strong>ThirdPartyPojo.java</strong></p>
  
  <pre><code>public class ThirdPartyPojo implements java.io.Serializable {
  
      private String name;
      private String ssid;
      private Integer id;
  
      //public setters and getters
  
  }
  </code></pre>
  
  <p>Above class is part of third party jar which we are using as below.</p>
  
  <pre><code>ThirdPartyPojo result = someDao.getData(String id);
  </code></pre>
  
  <p>Now our plan is as <code>ThirdPartyPojo</code> is part of third party jar, we cannot send <code>ThirdPartyPojo</code> result type directly to clients. we want to create our own pojo which will have same properties as <code>ThirdPartyPojo.java</code> class. we have to set the data from ThirdPartyPojo.java to <code>OurOwnPojo.java</code> and return it as below.</p>
  
  <pre><code>public OurOwnPojo getData(String id){
  
      ThirdPartyPojo result = someDao.getData(String id)
  
      OurOwnPojo response = new OurOwnPojo(result);
  
      return response;
  
      //Now we have to populate above `result` into **OurOwnPojo** and return the same.
  
  }
  </code></pre>
  
  <p>Now I want to know if there is a best way to have same properties in <code>OurOwnPojo.java</code> as <code>ThirdPartyPojo.java</code> and populate the data from <code>ThirdPartyPojo.java</code> to <code>OurOwnPojo.java</code> and return the same?</p>
  
  <pre><code>public class OurOwnPojo implements java.io.Serializable {
  
      private ThirdPartyPojo pojo;
  
      public OurOwnPojo(ThirdPartyPojo pojo){
  
           this.pojo = pojo
      }
  
  
      //Now here i need to have same setter and getters as in ThirdPartyPojo.java
  
      //i can get data for getters from **pojo**
  
  }
  </code></pre>
  
  <p>Thanks!</p>