springspring-bootspring-data-restspring-hateoashal-json

Missing paging arguments in generated HAL self link


I am using Spring Boot (2.1.1) to automatically create an HAL REST API of my JpaRepository interfaces.

For most cases these interfaces are empty, for example:

public interface LevelRepository extends JpaRepository<Level, Long> {}

When I open my REST base path, the following link is generated for levels:

"levels": {
  "href": "http://localhost:8080/admin/levels{?page,size,sort}",
  "templated": true
} 

When I follow http://localhost:8080/admin/levels?size=10 I get the expected page 0 and its 10 elements. But the given self link is:

"self": {
  "href": "http://localhost:8080/admin/levels{&sort}",
  "templated": true
}

I would have expected:

I am not sure if this is a bug or a feature? Is it possible to get the expected behavior?

I have found the following question on the topic: Error on generating self link on pageable resource But the given solution does not help, as I am already using a newer version.

Further informations (Why do I need it?)

This behavior breaks the flow of following links on the client side. If the user wants to jump directly to page X or if he wants to change the page size, the original link must be reused. Not a big workaround, but it is not as nice as templating and following the given self link directly.


Solution

  • After posting this question I found the following Spring JIRA ticket describing the same behavior. According to a comment in the ticket the self link should not be templated.

    Although the generated self link is templated, it is probably better to ignore the given parameters.