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

Issues with jackson serialization of `org.springframework.data.web.PagedModel`

Open
#3,327 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Jul 21, 2025.

type: enhancement
Dominant language
Java
Stars
838
Forks
730
PR merge metrics
No merged PRs in 30d

Description

In a Spring Boot @RestController, a response of org.springframework.data.web.PagedModel<T> is currently serialized differently from a response of type List<T> . In particular, if polymorphic serialization is specified for type <T> via JsonTypeInfo and JsonSubTypes, these will be applied for List<T> but not currently for PagedModel<T>. This results in behaviour that is unexpected which also leaves one with no simple way of achieving polymorphic serialization while using PagedModel.

The default serialization configuration for Spring framework depends closely on this code from Spring Framework's AbstractJackson2HttpMessageConverter.java.

if (type != null && TypeUtils.isAssignable(type, value.getClass())) {
    javaType = getJavaType(type, null);
}

With this default code from Spring Framework, PagedModel<T> is classified as a SimpleType, while List<T> is defined as a CollectionType. This then impacts Spring Framework's choice of ObjectWriter.

It would be helpful if Spring Data supplied (and maintained) the additional Jackson configuration that is needed to ensure that PagedModel<T> will serialize similarly in relevant ways to List<T>.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.