spring-projects / spring-projects/spring-data-commons

Provide a SlicedModel DTO to render stable JSON representations of Slice

Open
#3,516 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
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:

  1. Serialize SliceImpl as-is, with the same instability PagedModel exists to avoid (and without the PlainPageSerializationWarning that flags the problem for pages).
  2. Adopt Spring HATEOAS and SlicedResourcesAssembler (#1307), which is the documented answer but changes the payload to HAL.
  3. Create a dedicated custom SlicedModel DTO 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.