title: Pattern to map JPA Objects to DTO for Conversion to JSON
body: <p>I have a somewhat philosophical question relating to mapping JPA Objects to JSON Strings.  Of course there is no necessity for the source object to be a persistent object - it is just that that is my situation.  </p>
  
  <p>I have a collection of objects that are managed by Eclipse Link.  I need to turn some of these objects into JSON Strings, however the mapping is not one-to-one.  I am convinced that the conversion should be loosely coupled so as to isolate the JSON objects from changes in the underlying entities.  </p>
  
  <p>I am planning to have the JPA entity as such:</p>
  
  <pre><code>@Entity
  @Table(name = "AbnormalFlags")
  public class AbnormalFlag  implements java.io.Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      @Column(name = "Code", unique = false, nullable = false)
      private String code;
  
      @Column(name = "Description", unique = false, nullable = false)
      private String description;
  
  // Getters and setters
  
  }
  </code></pre>
  
  <p>and the equivalent object to be converted to JSON</p>
  
  <pre><code>public class AbnormalFlagDTO  implements java.io.Serializable {
  
      private String code;
      private String description;
      private Boolean disabled;
  
  // Getters and setters
  
  }
  </code></pre>
  
  <p>Is there an elegant pattern or methodology I can use to facilitate this process for several types of objects.</p>
  
  <p>Thanks in anticipation</p>