javaspringspring-dataspring-data-rest

Spring @RepositoryRestController causes @PageableDefault to stop working


I have a custom controller that is using the @PageableDefault annotation. I was using @Controller annotation on my class, however, I wanted to make this controller respond with the HATEOAS response. I added the @RepositoryRestController changed my method to

public HttpEntity<PagedResources<Resource<Books>>> search(
                      @RequestParam(value = "q", required = false) String query,
                      @PageableDefault(page = 0, size = 20) Pageable pageable)

and then the return to

return new ResponseEntity<PagedResources<Resource<Books>>> booksAssembler
                                               .toResource(queryResult), HttpStatus.OK);

Now my @PageableDefault doesn't work. But when a client make a request (e.g. explicitly adding (or without) &page=0&size=20 to the URL) the endpoint from the controller, pageable is always null. I don't get why it stop working after changing the annotation? Is there any way to fix it other than changing back to @Controller?


Solution

  • I found the solution.

    I was running into this bug. https://jira.spring.io/browse/DATAREST-906

    I was using Spring Boot 1.4.1, upgrading to 1.4.2 solves the problem.