title: Best practice to convert list object to list objectDto java
body: <p>I have done do get all my data and convert from object to objectDto. But, somehow, I feel like my code is not good yet. Here I need your help, I need any reference/advice to make my code better (in performance). Here is my working code:</p>
  
  <pre><code>    @Override
      public List&lt;BookDto&gt; findAll() throws Exception {
          try {
              List&lt;Book&gt; list = bookDao.findAll();
              List&lt;BookDto&gt; listDto = new ArrayList&lt;&gt;();
  
              for (Book book : list) {
                  BookDto bookDto = new BookDto();
                  Set&lt;AuthorDto&gt; listAuthorDto = new HashSet&lt;AuthorDto&gt;();
                  Set&lt;Author&gt; dataAuthor = new HashSet&lt;Author&gt;();
                  book.getAuthor().iterator().forEachRemaining(dataAuthor::add);
  
                  BeanUtils.copyProperties(book, bookDto, "author", "category");
                  bookDto.setCategory(book.getCategory().getCategory());
  
                  for (Author author : dataAuthor) {
                      AuthorDto authorDto = new AuthorDto();
                      BeanUtils.copyProperties(author, authorDto);
                      listAuthorDto.add(authorDto);
                  }
  
                  bookDto.setAuthor(listAuthorDto);
                  listDto.add(bookDto);
              }
              return listDto;
          } catch (Exception e) {
              throw new Exception(e);
          }
      }
  </code></pre>
  
  <p>and here is the output that I need (already achieved with above code):</p>
  
  <pre><code>[
      {
          "title": "book1",
          "year": "2013",
          "author": [
              {
                  "name": "john",
                  "address": "NY"
              },
              {
                  "name": "angel",
                  "address": "LA"
              }
          ],
          "category": "science"
      },
      {
          "title": "book2",
          "year": "2014",
          "author": [
              {
                  "name": "john",
                  "address": "NY"
              }
          ],
          "category": "science"
      },
      {
          "title": "book3",
          "year": "2009",
          "author": [
              {
                  "name": "angel",
                  "address": "LA"
              }
          ],
          "category": "comedy"
      }
  ]
  </code></pre>