spring-projects / spring-projects/spring-data-commons
Issues with jackson serialization of `org.springframework.data.web.PagedModel`
@odrotbohm is already working on this.
Since Jul 21, 2025.
- 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
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.
Assessment
This issue has not been assessed yet.