title: Replacing entire contents of spring-data Page, while maintaining paging info
body: <p>Using spring-data-jpa and working on getting data out of table where there are about a dozen columns which are used in queries to find particular rows, and then a payload column of clob type which contains the actual data that is marshalled into java objects to be returned.</p>
  
  <p>Entity object very roughly would be something like</p>
  
  <pre><code>@Entity
  @Table(name = "Person")
  
  public class Person {
      @Column(name="PERSON_ID", length=45) @Id private String personId;
      @Column(name="NAME", length=45) private String name;
      @Column(name="ADDRESS", length=45) private String address;
      @Column(name="PAYLOAD") @Lob private String payload;
  
      //Bunch of other stuff
  } 
  </code></pre>
  
  <p>(Whether this approach is sensible or not is a topic for a different discussion)</p>
  
  <p>The clob column causes performance to suffer on large queries ... </p>
  
  <p>In an attempt to improve things a bit, I've created a separate entity object ... sans payload ...</p>
  
  <pre><code>@Entity
  @Table(name = "Person")
  
  public class NotQuiteAWholePerson {
      @Column(name="PERSON_ID", length=45) @Id private String personId;
      @Column(name="NAME", length=45) private String name;
      @Column(name="ADDRESS", length=45) private String address;
  
      //Bunch of other stuff
  } 
  </code></pre>
  
  <p>This gets me a page of NotQuiteAPerson ... I then query for the page of full person objects via the personIds.</p>
  
  <p>The hope is that in not using the payload in the original query, which could filtering data over a good bit of the backing table, I only concern myself with the payload when I'm retrieving the current page of objects to be viewed ... a much smaller chunk.</p>
  
  <p>So I'm at the point where I want to map the contents of the original returned Page of NotQuiteAWholePerson to my List of Person, while keeping all the Paging info intact, the map method however only takes a Converter which will iterate over the NotQuiteAWholePerson objects ... which doesn't quite fit what I'm trying to do.</p>
  
  <p>Is there a sensible way to achieve this ?</p>
  
  <hr>
  
  <p>Additional clarification for @itsallas as to why existing map() will not suffice..</p>
  
  <p>PageImpl::map has</p>
  
  <pre><code>@Override
  public &lt;S&gt; Page&lt;S&gt; map(Converter&lt;? super T, ? extends S&gt; converter) {
      return new PageImpl&lt;S&gt;(getConvertedContent(converter), pageable, total);
  }
  </code></pre>
  
  <p>Chunk::getConvertedContent has</p>
  
  <pre><code>protected &lt;S&gt; List&lt;S&gt; getConvertedContent(Converter&lt;? super T, ? extends S&gt; converter) {
  
      Assert.notNull(converter, "Converter must not be null!");
  
      List&lt;S&gt; result = new ArrayList&lt;S&gt;(content.size());
  
      for (T element : this) {
          result.add(converter.convert(element));
      }
  
      return result;
  }
  </code></pre>
  
  <p>So the original List of contents is iterated through ... and a supplied convert method applied, to build a new list of contents to be inserted into the existing Pageable.</p>
  
  <p>However I cannot convert a NotQuiteAWholePerson to a Person individually, as I cannot simply construct the payload... well I could, if I called out to the DB for each Person by Id in the convert... but calling out individually is not ideal from a performance perspective ... </p>
  
  <p>After getting my Page of NotQuiteAWholePerson I am querying for the entire List of Person ... by Id ... in one call ... and now I am looking for a way to substitute the entire content list ... not interively, as the existing map() does, but in a simple replacement.</p>
  
  <p>This particular use case would also assist where the payload, which is json, is more appropriately persisted in a NoSql datastore like Mongo ... as opposed to the sql datastore clob ...</p>
  
  <p>Hope that clarifies it a bit better.</p>