spring-projects / spring-projects/spring-data-commons
Provide a SlicedModel DTO to render stable JSON representations of Slice
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 838
- Forks
- 730
- PR merge metrics
- No merged PRs in 30d
Description
org.springframework.data.web.PagedModel was introduced in 3.3 via #3024 as a middle ground between serializing PageImpl directly and adopting Spring HATEOAS. There is currently no equivalent for Slice.
Problem
The rationale in #3024 applies equally to slices. SliceImpl is a domain type, so its JSON representation carries the same stability risk that motivated PagedModel — but returning a Slice from a controller today leaves three options, none good:
- Serialize
SliceImplas-is, with the same instabilityPagedModelexists to avoid (and without thePlainPageSerializationWarningthat flags the problem for pages). - Adopt Spring HATEOAS and
SlicedResourcesAssembler(#1307), which is the documented answer but changes the payload to HAL. - Create a dedicated custom
SlicedModelDTO per project.
Proposal
A SlicedModel<T> in org.springframework.data.web, mirroring PagedModel in shape and usage:
@GetMapping("/slice")
SlicedModel<?> slice(Pageable pageable) {
return new SlicedModel<>(repository.findAllBy(pageable));
}
{
"content": [ ... ],
"page": { "size": 20, "number": 0, "numberOfElements": 20, "hasNext": true }
}
Deliberately no totalElements/totalPages, since that information is exactly what a Slice does not have.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with org.springframework.data.web.PagedModel and the Slice/SliceImpl types to understand the existing shape and usage. Add the corresponding stable SlicedModel representation without totalElements or totalPages, then verify its JSON shape against the example and existing PagedModel behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100