I need to have a custom pagination with request and response objects, in request I need page, size, and totalCountOfApplicants, which I am searching using MongoDB. I have created an endpoint that filters the applicants for various fields, I just need to add the count of totalApplicants.
public class PaginationRequest implements Serializable {
private static final long serialVersionUID = 1L;
private int pageNumber = 0;
private int pageSize=20;
private int totalApplicants;
}
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class PaginationResponse extends Response {
private static final long serialVersionUID = 1L;
private Pageable pageable;
}
Mongo code to find the total number of applicants
request.getPaginationRequest().setTotalApplicants((int) mongoTemplate.count(query, Applicant.class));
I am getting a NullPointerException in this line when I try to find the number of pages during validation.
int page = request.getPaginationRequest().getPageNumber(), size = request.getPaginationRequest().getPageSize();
I am just a beginner, so please provide any relevant info you have.