spring-data-commons
spring-data-commons copied to clipboard
No TemplateVariable generated for null Pageable [DATACMNS-1752]
Réda Housni Alaoui opened DATACMNS-1752 and commented
We use:
- Spring Data Commons 2.3.0
- Spring Data JPA 2.3.0
- Spring HATEOAS 1.1.0
HateoasPageableHandlerMethodArgumentResolver is registered in the Spring context.
Given the following controller:
@Controller
@RequestMapping("/")
public static class MyController {
private final WebMvcLinkBuilderFactory webMvcLinkBuilderFactory;
public MyController(WebMvcLinkBuilderFactory webMvcLinkBuilderFactory) {
this.webMvcLinkBuilderFactory = webMvcLinkBuilderFactory;
}
@GetMapping
public ResponseEntity<?> links() {
return ResponseEntity.ok(
new RepresentationModel<>(
Collections.singletonList(
webMvcLinkBuilderFactory
.linkTo(methodOn(MyController.class).pageable(null))
.withRel("pageable"))));
}
@GetMapping("/pageable")
public ResponseEntity<?> pageable(Pageable pageable) {
return ResponseEntity.noContent().build();
}
}
Querying / with accept: application/hal+json produces:
{
"_links": {
"pageable": {
"href": "http://localhost/pageable"
}
}
}
We were expecting the link to be templated with the following optional variables:
- page
- size
The issue on the Spring HATEOAS side is https://github.com/spring-projects/spring-hateoas/issues/706
How to fix that?
Affects: 2.3.1 (Neumann SR1)
Please note that https://github.com/spring-projects/spring-hateoas/issues/706 can be fixed by applying https://github.com/spring-projects/spring-hateoas/pull/1312 . After that, a pull request inspired by https://github.com/Cosium/spring-data-commons/commit/b9600b18b8bd94fefb10ef85ee0c72ff9b4225c0 fixes the current issue.