title: Why I have StackOverFlow when i try convert my DTO
body: <p>When I try to fetch my tasks I have StackOverflowError that is bellow. I think that this error because of my mapper, do u know how can I change my mapper for work next code?
  This is my Task Entity class:</p>
  <pre><code>@NamedNativeQueries({
          @NamedNativeQuery(name = SELECT_TASKS,
                  query = &quot;SELECT * from tasks&quot;,
                  resultClass = Task.class),
          @NamedNativeQuery(name = DELETE_REJECTED_TASKS,
                  query = &quot;DELETE FROM tasks WHERE status = 0 AND CURRENT_DATE - :&quot; + PARAMETER_DURATION + &quot; &gt; creation_date&quot;,
                  resultClass = Task.class),
          @NamedNativeQuery(name = FIND_REJECTED_TASKS,
                  query = &quot;SELECT * FROM tasks WHERE status = 0 AND CURRENT_DATE - :&quot; + PARAMETER_DURATION + &quot; &gt; creation_date&quot;,
                  resultClass = Task.class),
          @NamedNativeQuery(name = SELECT_TASKS_BY_ASSIGNED_USER_ID,
                  query = &quot;select * from tasks inner join users u on tasks.user_id = u.id where user_id = :&quot; + PARAMETER_USER_ID,
                  resultClass = Task.class)
  })
  @Data
  @AllArgsConstructor
  @NoArgsConstructor
  @EqualsAndHashCode
  @ToString
  @Builder
  @Entity
  @Table(name = &quot;tasks&quot;)
  public class Task{
  
      @Id
      @Column(name = &quot;id&quot;)
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @Column(name = &quot;name&quot;)
      private String name;
  
      @Column(name = &quot;description&quot;)
      private String description;
  
      @Column(name = &quot;creation_date&quot;)
      private LocalDateTime creationDate;
  
      @Enumerated(EnumType.ORDINAL)
      @Column(name = &quot;priority&quot;)
      private Priority priority;
  
      @Enumerated(EnumType.ORDINAL)
      @Column(name = &quot;status&quot;)
      private Status status;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = &quot;user_id&quot;)
      User user;
  
      @PrePersist
      private void setUp() {
          this.creationDate = LocalDateTime.now();
          this.status = Status.TODO;
      }
  }
  
  </code></pre>
  <p>I have this User Entity</p>
  <pre><code>@Data
  @ToString
  @AllArgsConstructor
  @NoArgsConstructor
  @EqualsAndHashCode
  @Builder
  @Entity
  @Table(name = &quot;users&quot;)
  public class User{
  
      public static final String SELECT_USERS = &quot;selectUsers&quot;;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
      @Column(name = &quot;first_name&quot;)
      private String firstName;
      @Column(name = &quot;last_name&quot;)
      private String lastName;
      @Column(name = &quot;email&quot;)
      private String email;
  
      @OneToOne
      @JoinColumn(name = &quot;statistic_id&quot;, referencedColumnName = &quot;id&quot;)
      private UserStatistic userStatistic;
  
      @OneToMany(mappedBy = &quot;user&quot;, fetch = FetchType.LAZY)
  //    @JsonManagedReference
      @ToString.Exclude
      @JsonIgnore
      List&lt;Task&gt; taskList = new ArrayList&lt;&gt;();
  }
  
  </code></pre>
  <p>And this DTO</p>
  <pre><code>package ua.zhytariuk.planningsystem.model.dto;
  
  import com.fasterxml.jackson.annotation.JsonBackReference;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonManagedReference;
  import lombok.*;
  import ua.zhytariuk.planningsystem.model.domain.User;
  import ua.zhytariuk.planningsystem.model.enums.Priority;
  import ua.zhytariuk.planningsystem.model.enums.Status;
  
  import java.time.LocalDateTime;
  
  /**
   * Class that provide DTO pattern
   *
   * @author Zhytariuk Oleksandr
   */
  @Data
  @AllArgsConstructor
  @NoArgsConstructor
  @EqualsAndHashCode
  @ToString
  @Builder
  public class TaskDTO {
  
      private Long id;
  
      private String name;
      private String description;
      private LocalDateTime creationDate;
      private Priority priority;
      private Status status;
  
      private UserDTO userDTO;
  }
  
  </code></pre>
  <p>this task mapper</p>
  <pre><code>package ua.zhytariuk.planningsystem.model.mapper;
  
  import lombok.RequiredArgsConstructor;
  import lombok.extern.slf4j.Slf4j;
  import org.springframework.context.annotation.Lazy;
  import org.springframework.stereotype.Component;
  import ua.zhytariuk.planningsystem.model.domain.Task;
  import ua.zhytariuk.planningsystem.model.dto.TaskDTO;
  
  /**
   * Class that provide methods for converting {@link Task} to {@link TaskDTO}
   *
   * @author Zhytariuk Oleksandr
   */
  @Slf4j
  @Component
  @RequiredArgsConstructor(onConstructor = @__(@Lazy))
  public class TaskMapper {
  
      private final UserMapper userMapper;
  
      /**
       * Convert task to taskDTO
       *
       * @param task param that need to convert
       * @return taskDTO
       */
      public TaskDTO convertToTaskDTO(Task task) {
  
          return TaskDTO.builder()
                  .id(task.getId())
                  .creationDate(task.getCreationDate())
                  .description(task.getDescription())
                  .name(task.getName())
                  .status(task.getStatus())
                  .priority(task.getPriority())
                  .userDTO(userMapper.convertToUserDTO(task.getUser()))
                  .build();
      }
  
      /**
       * Convert taskDTO to task
       *
       * @param taskDTO param that need to convert
       * @return task
       */
      public Task convertTaskDTOtoTask(TaskDTO taskDTO) {
  
          return Task.builder()
                  .id(taskDTO.getId())
                  .creationDate(taskDTO.getCreationDate())
                  .description(taskDTO.getDescription())
                  .name(taskDTO.getName())
                  .status(taskDTO.getStatus())
                  .user(userMapper.convertUserDTOtoUser(taskDTO.getUserDTO()))
                  .priority(taskDTO.getPriority())
                  .build();
      }
  }
  
  </code></pre>
  <p>Ok for fetch task i have next method in my controller:</p>
  <pre><code>    @GetMapping(&quot;{taskId}&quot;)
      public ResponseEntity&lt;TaskDTO&gt; fetchTask(@PathVariable Long taskId) throws TaskDAOException {
          log.info(&quot;FetchTask.E with Task id: {}&quot;, taskId);
          final Task task = taskService.findById(taskId);
          if (Objects.isNull(task)) {
              throw new TaskNotFoundException(&quot;Task with id &quot; + taskId + &quot; was not found&quot;);
          }
          final TaskDTO taskDTO = taskMapper.convertToTaskDTO(task);
          log.info(&quot;FetchTask.X with TaskDTO: {}&quot;, taskDTO);
          return new ResponseEntity&lt;&gt;(taskDTO, HttpStatus.OK);
      }
  </code></pre>
  <p>When I try to fetch my Task that have User I have next Error. What I should to do for resolve it</p>
  <pre><code>java.lang.StackOverflowError: null
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.9.jar:5.3.9]
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.3.9.jar:5.3.9]
      at ua.zhytariuk.planningsystem.model.mapper.TaskMapper$$EnhancerBySpringCGLIB$$d6858996.convertToTaskDTO(&lt;generated&gt;) ~[classes/:?]
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[?:?]
      at java.util.Iterator.forEachRemaining(Iterator.java:133) ~[?:?]
      at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[?:?]
      at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[?:?]
      at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[?:?]
      at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[?:?]
      at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
      at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[?:?]
      at ua.zhytariuk.planningsystem.model.mapper.UserMapper.convertToUserDTO(UserMapper.java:37) ~[classes/:?]
      at ua.zhytariuk.planningsystem.model.mapper.UserMapper$$FastClassBySpringCGLIB$$a7183b9d.invoke(&lt;generated&gt;) ~[classes/:?]
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.9.jar:5.3.9]
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.3.9.jar:5.3.9]
      at ua.zhytariuk.planningsystem.model.mapper.UserMapper$$EnhancerBySpringCGLIB$$79812a8.convertToUserDTO(&lt;generated&gt;) ~[classes/:?]
      at ua.zhytariuk.planningsystem.model.mapper.TaskMapper.convertToTaskDTO(TaskMapper.java:37) ~[classes/:?]
      at ua.zhytariuk.planningsystem.model.mapper.TaskMapper$$FastClassBySpringCGLIB$$8203d1d7.invoke(&lt;generated&gt;) ~[classes/:?]
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.9.jar:5.3.9]
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.3.9.jar:5.3.9]
      at ua.zhytariuk.planningsystem.model.mapper.TaskMapper$$EnhancerBySpringCGLIB$$d6858996.convertToTaskDTO(&lt;generated&gt;) ~[classes/:?]
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[?:?]
      at java.util.Iterator.forEachRemaining(Iterator.java:133) ~[?:?]
      at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[?:?]
      at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[?:?]
      at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[?:?]
      at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[?:?]
      at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
      at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[?:?]
      at ua.zhytariuk.planningsystem.model.mapper.UserMapper.convertToUserDTO(UserMapper.java:37) ~[classes/:?]
      at ua.zhytariuk.planningsystem.model.mapper.UserMapper$$FastClassBySpringCGLIB$$a7183b9d.invoke(&lt;generated&gt;) ~[classes/:?]
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.9.jar:5.3.9]
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.3.9.jar:5.3.9]
      at ua.zhytariuk.planningsystem.model.mapper.UserMapper$$EnhancerBySpringCGLIB$$79812a8.convertToUserDTO(&lt;generated&gt;) ~[classes/:?]
      at ua.zhytariuk.planningsystem.model.mapper.TaskMapper.convertToTaskDTO(TaskMapper.java:37) ~[classes/:?]
      at ua.zhytariuk.planningsystem.model.mapper.TaskMapper$$FastClassBySpringCGLIB$$8203d1d7.invoke(&lt;generated&gt;) ~[classes/:?]
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.9.jar:5.3.9]
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.3.9.jar:5.3.9]
      at ua.zhytariuk.planningsystem.model.mapper.TaskMapper$$EnhancerBySpringCGLIB$$d6858996.convertToTaskDTO(&lt;generated&gt;) ~[classes/:?]
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[?:?]
      at java.util.Iterator.forEachRemaining(Iterator.java:133) ~[?:?]
      at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[?:?]
      at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[?:?]
      at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[?:?]
      at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[?:?]
      at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
      at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[?:?]
  </code></pre>