Skip to content

Provide means to render simplified JSON representations of PageImpl easily #3024

Closed
@odrotbohm

Description

@odrotbohm

As a follow-up to #2987 we're looking into providing a means to easily have PageImpl instances rendered in a simplified, stable JSON representation when returned from Spring MVC controller methods. Currently, PageImpl is serialized as is exposing internals. The representation would also change should we ever need to change the class' API for unrelated reasons.

The currently suggested better way is to rather use Spring HATEOAS PagedModel. While that's the best option overall, it requires an additional dependency and the user to decide for a hypermedia type to render the navigational links properly. This might not be desirable in all cases.

As a middle ground, we're going to introduce a Spring Data PagedModel, that is a structural equivalent of the Spring HATEOAS' one but avoids adding links as navigational elements. The type can then be used in controllers explicitly (through page.map(PagedModel::new), or get applied globally by configuring @EnableSpringDataWebSupport(paginationSerializationMode = VIA_DTO). Not enabling that explicitly is going to cause a warning log issued that outlines the dangers of serializing PageImpl directly and suggesting the better ways of handling the situation (either Spring Data's or Spring HATEOAS PagedModel).

Metadata

Metadata

Assignees

Labels

in: webIntegration with Spring MVCtype: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions