Reputation: 25
I am accepting a paginated response from service and performing an operation on it. which results in to a singular object. object which contains aggregation queryResult from mongo, How to return paginated response of objects within a single object from endpoint.
{
"fullName:"abc",
"educationData":[
// paginated response from another service.
//queryResult
],
"cellNo" : "12345",
"address" : "pqr";
}
I want to paginate list of "educationData", but I ended up paginating entire object.
Upvotes: 1
Views: 530
Reputation: 405
As you are already receiving a paginated response from a service, you can carry forward the same response. Create a class which implements PageImpl which will give you all the pagination information for eg:-
public class CustomPageImpl extends PageImpl<T> {
@JsonCreator
@JsonIgnoreProperties(ignoreUnknown = true)
public CustomPageImpl(@JsonProperty("content") List<T> content,
@JsonProperty("number") int page,
@JsonProperty("size") int size,
@JsonProperty("totalElements") long totalElements) {
super(content, new PageRequest(page, size), totalElements);
}
}
change your response object and append these fields from CustomPageImpl class.
{
"fullName:"abc",
"educationData":[
// paginated response from another service.
//queryResult
],
"cellNo" : "12345",
"address" : "pqr",
"totalElements": 0,
"totalPages": 0
}
Upvotes: 1