title: Convert type of Spring Data JPA Page content
body: <p>I am using Spring Data JPA and I have a <code>PagingAndSortingRepository&lt;Contact, Long&gt;</code> that uses a <code>JPASpecificationExecutor&lt;Contact&gt;</code>. I pass a <code>Specification</code> and a <code>Pageable</code> instance to the <code>.findAll()</code> method of this repository to get a <code>Page&lt;Contact&gt;</code>.</p>
  
  <p>However, my <code>Contact</code> entity has a lot of extra fields and mappings that I don't need on my front end. So, I have a <code>ContactDto</code> that contains only the necessary fields, and I have a method that can convert from <code>Contact</code> to <code>ContactDto</code>.</p>
  
  <pre><code>private ContactDto convertToContactDto(Contact contact) {
      //do the conversion
  }
  </code></pre>
  
  <p>How would I go about using this conversion method to convert the <code>Page&lt;Contact&gt;</code> to a <code>Page&lt;ContactDto&gt;</code>?</p>
  
  <p>I can get the content of the <code>Page&lt;Contact&gt;</code> and do the conversion like this.</p>
  
  <pre><code>final Page&lt;Contact&gt; contactPage = pagingAndSortingContactRepository
          .findAll(ContactSpecification.findByFirstNmLike(firstNm), pageable);
  
  final Collection&lt;ContactDto&gt; contactDtos = contactPage.getContent()
      .stream()
      .map(this::convertToContactDto)
      .collect(Collectors.toList());
  </code></pre>
  
  <p>But then I am left with a <code>Collection</code> instead of a <code>Page</code>, and I don't know how to get that <code>Collection</code> into the content of the <code>Page</code>. Is there a way to do this? Or is there another way to call the conversion on the <code>Page&lt;Contact&gt;</code> instance itself?</p>