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>
.