title: Spring Boot Pagination
body: <p>I'm facing the problem for pagination data. Page data is getting calculated using the outer array <code>dXPRecommendationResponses</code> where I want it should be calculated through the nested array <code>recommendations</code>. I've mentioned the response data in result section.</p>
  
  <p>I tried to change the page data calculation but it is getting calculated using the the data which we are passing in <code>PageImpl()</code> constructor.</p>
  
  <p>I've used this approach to paginate the data which we are getting from third party API.</p>
  
  <p>But it is getting calculated using the <code>dxpRecommendationslist</code>.</p>
  
  <pre><code>#This is the code through I need to generate the response
  List&lt;DXPRecommendationResponse&gt; dxpRecommendationslist = new ArrayList&lt;&gt;();
  
  List&lt;DXPActivity&gt; dxpActivities = getThirdResponse(pageable, correlationId,
  dxpRecommendationslist, reservationGuestId, reservationId, nbxRecommendationRequest);
  
  return new PageImpl&lt;&gt;(dxpRecommendationslist, pageable, dxpActivities.size());
  
  #This method is used to get data from third party
  public List&lt;DXPActivity&gt; getThirdResponse(final Pageable pageable, final String correlationId,
          List&lt;DXPRecommendationResponse&gt; list, String reservationGuestId, String reservationId,
          NBXRecommendationRequest nbxRecommendationRequest) {
  
      List&lt;DXPActivity&gt; dxpActivities = new ArrayList&lt;&gt;();
  
      NBXRecommendationResponse nbxRecommendationResponse = vVNBXRecommendationService
              .getCalendarRecommendation(nbxRecommendationRequest, correlationId);
  
      if (nbxRecommendationResponse != null) {
  
          DXPRecommendationResponse dxpRecommendationResponse = new DXPRecommendationResponse();
          dxpRecommendationResponse.setReservationGuestId(reservationGuestId);
          dxpRecommendationResponse.setReservationNumber(reservationId);
          dxpRecommendationResponse.setRecommendationType("CalendarType");
          dxpRecommendationResponse.setDateTime(new Date());
  
          populateActivities(dxpActivities, nbxRecommendationResponse);
          List&lt;DXPActivity&gt; filteredList;
          if (!CollectionUtils.isEmpty(dxpActivities)
                  &amp;&amp; dxpActivities.size() &gt;= (pageable.getPageSize() * pageable.getPageNumber())) {
  
              filteredList = Lists.partition(dxpActivities, pageable.getPageSize()).get(pageable.getPageNumber());
          } else {
  
              filteredList = new ArrayList&lt;DXPActivity&gt;();
          }
          dxpRecommendationResponse.setRecommendations(filteredList);
          list.add(dxpRecommendationResponse);
      }
  
      return dxpActivities;
  }
  #This method is used to populate data
  private void populateActivities(List&lt;DXPActivity&gt; dxpActivities,
          NBXRecommendationResponse nbxRecommendationResponse) {
  
      for (Activity activity :nbxRecommendationResponse.getCalendarRecommendation().getRecommendations().getActivities()) {
  
          DXPActivity dxpActivity = new DXPActivity();
          orikaMapper.map(activity, dxpActivity);
          dxpActivities.add(dxpActivity);
      }
  }
  </code></pre>
  
  <p>The response data:</p>
  
  <pre><code>{
      "_embedded": {
          "dXPRecommendationResponses": [
          {
              "recommendationType": "CalendarType",
              "reservationGuestId": "525dab66-1492-4908-a3bf-b5de558368e5",
              "reservationNumber": "3a39f9ad-7e34-4bdb-91eb-b907fd6986c7",
              "dateTime": "2019-08-19T14:38:18.413",
              "recommendations": [
              {
                  "productCode": "BIKE2006111000",
                  "activityName": "Bimini Bike Tour",
                  "recommendationId": "1565948843492_410387839_BIKE2006111000_cal",
                  "categoryCode": "DARING",
                  "activityStartTime": "2020-06-11T08:30:00.000",
                  "activityEndTime": "2020-06-11T11:30:00.000",
                  "activityDescription": "Bimini Bike Tour",
                  "sequence": 34.0,
                  "packageId": 103806,
                  "sourceId": "BIMINI BIKE",
                  "levelOfActivity": "EASY"
              },
              {
                  "productCode": "CUL2006110900",
                  "activityName": "Bimini Culinary Tour",
                  "recommendationId":"156594884349, 
                  "categoryCode": "CULTURED",
                  "activityStartTime": "2020-06-11T07:30:00.000",
                  "activityEndTime": "2020-06-11T12:30:00.000",
                  "activityDescription": "Bimini Culinary Tour",
                  "sequence": 29.0,
                  "packageId": 103940,
                  "sourceId": "BIMINI CUL",
                  "levelOfActivity": "MODERATE"
              }
              ]
          }
          ]
      },
      "page": {
          "size": 10,
          "totalElements": 1,
          "totalPages": 1,
          "number": 0
      }
  }
  </code></pre>