PagedModel does not paginate a custom repository result on its own. To return Spring HATEOAS navigation links, have the repository provide a correctly populated Spring Data Page<T>, then pass that page to PagedResourcesAssembler.toModel(...). First check which PagedModel class you imported: Spring Data’s simplified metadata model and Spring HATEOAS’s linked representation are separate types.
Why a custom repository result does not become a paginated HATEOAS response
Several different problems can look like “PagedModel doesn’t work.” The repository may return a list or custom DTO instead of a Spring Data Page; the endpoint may import the other PagedModel; or a representation may be constructed without page metadata or navigation links. Returning a model object does not itself run the HATEOAS pagination-link assembly step.
As an Amazon Associate I earn from qualifying purchases.
Spring Data’s PagedResourcesAssembler API documents conversion from a Spring Data Page<T> to a HATEOAS PagedModel. A list does not, in general, establish the total number of matching records or the metadata needed to describe a page correctly.
Check which PagedModel you mean
The two similarly named classes have different purposes. Verify the fully qualified import in your controller and the response contract expected by the client.
#1 Best Overall
| Type or approach | Input | What it provides | Use it when |
|---|---|---|---|
org.springframework.hateoas.PagedModel with PagedResourcesAssembler |
Spring Data Page<T> |
HATEOAS representation with page navigation links assembled from the request or a supplied self link | Clients need hypermedia navigation |
org.springframework.data.web.PagedModel |
Spring Data Page<T> |
Simplified page JSON with metadata; it does not provide HATEOAS navigation links | You need a stable metadata envelope, not hypermedia links |
Manually created HATEOAS PagedModel |
Content, explicit metadata, and optional links | Only the metadata and links you supply | Your application deliberately owns and validates the representation |
SlicedResourcesAssembler |
Spring Data Slice<T> |
Slice-oriented HATEOAS representation without claiming a total-page count | The query does not need a total count |
Spring Data documents its simplified model and the VIA_DTO page serialization option in the Spring Data JPA reference. Spring HATEOAS documents its separate PagedModel as a representation for pageable collection responses in the PagedModel API.
Return a Page from the custom query, then assemble it
Keep custom filtering and query logic in the repository. At the endpoint boundary, return a Spring Data Page<T> whose content, requested Pageable, and total count reflect the query, then convert it with the assembler.
Rank #2
@GetMapping("/items")
PagedModel<EntityModel<Item>> items(
Pageable pageable,
PagedResourcesAssembler<Item> assembler) {
Page<Item> page = repository.findCustomItems(pageable);
return assembler.toModel(page);
}
This is an illustrative shape, not a tested implementation. Adapt the element representation and endpoint links to your application, and confirm the APIs against your project’s dependency versions. Spring Data’s PagedResourcesAssembler documentation describes the Page-to-model conversion and assembler overloads.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Choose a valid path if the repository returns a List or Slice
If you have a List
A list alone cannot generally tell the framework how many matching records exist beyond the returned content. Change the repository method to return a suitable Page<T>, including a total count appropriate to the query, or intentionally construct a representation with metadata and links your application can substantiate. Spring HATEOAS exposes PagedModel.of(content, metadata, links) for explicit construction; see the PagedModel API.
Rank #3
If you have a Slice
When the query does not require a total count, use a slice-oriented response rather than presenting an unknown total as if it were known. The Spring Data JPA reference describes SlicedResourcesAssembler as the analogous conversion for a Slice and SlicedModel.
Check how pagination links are based
PagedResourcesAssembler can be configured with a pageable resolver and base URI. If its base URI is null, its API says toModel(Page) uses the current request URI to build relevant previous and next links. Overloads also accept a self link, letting the application choose a different link base.
Rank #4
The default assembler targets the controller method where it is invoked. Generated query parameters follow the pageable resolver configuration, so custom parameter names and defaults need to match the resolver used for link generation. See the assembler API and the Spring Data reference.
Use simplified page JSON only when links are not required
Spring Data’s org.springframework.data.web.PagedModel wraps a Page in a simplified metadata representation. The reference also documents @EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO) for simplified rendering of returned Page instances. This route does not add the navigation links produced by the Spring HATEOAS assembler; select it only if that matches the client contract.
Confirm version compatibility
The cited Spring Data Commons API page is labeled 4.1.0, and the Spring HATEOAS API pages are labeled 3.1.1; the Spring Data JPA reference is current. Your project’s versions were not specified, so check that the relevant overloads and configuration options exist in your dependencies before using the example unchanged.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




