title: JPA entities to DTO mapping creating deep copy
body: <p>I have class structure as below</p>
  
  <pre><code>@Entity
  @Table(name = "CourseGroups")
  public class CourseGroup {
  
      @Id
      @GeneratedValue
      long courseGroupId;
  
      @OneToMany(mappedBy = "courseGroup")
      @JsonManagedReference
      List&lt;Course&gt; courseList;
  
      //Getters and Setters
  }
  
  @Entity
  @Table(name = "Course")
  public class Course {
  
      @Id
      @GeneratedValue
      long courseId;
  
      @ManyToOne
      @JoinColumn(name = "courseGroupId")
      @JsonBackReference
      CourseGroup courseGroup;
  
      @OneToMany(mappedBy = "course",fetch = FetchType.LAZY)
      @JsonManagedReference
      List&lt;CoursePart&gt; courseParts;
  }
  
  @Entity
  @Table(name = "courseParts")
  public class CoursePart {
      @Id
      @GeneratedValue
      long  partId;
  
      @ManyToOne
      @JoinColumn(name = "courseid")
      @JsonBackReference
      Course course;
  
      @ManyToMany(mappedBy = "coursePartList")
      List&lt;Subject&gt; subjectsList;
  }
  
  </code></pre>
  
  <p>To return REST results I created DTO classes with almost the same fields. My main motive was to avoid the infinite nesting of objects happening when I directly return JPA entities from controller. </p>
  
  <pre><code>courseGroup{
    groupId,
     courseList:[
      { 
        courseId , 
        partList:[
                   {
                    partId,
                    subjectList:[ //Again Subject and So on]
                   }] 
       }
      ]
  }
  
  </code></pre>
  
  <p>So I used ModelMapper to map the entities to DTO classes but model mapper is again calling get for the List fields which is causing hibernate to load the lists and again list in list and so on.
   I can do @JsonIgnore but it ignores the list of object completely. What I want to do is return only certain level of nested lists and not all the nested lists.
  like </p>
  
  <pre><code>courseGroup{
    groupId,
     courseList:[
      { 
        courseId , 
        partList:[
                   {
                    partId, subjectId}] 
       }
      ]
  }
  </code></pre>
  
  <p>Is there any way in model mapper to map nested objects only till certain level and not complete object itself</p>