특정 원데이 클래스에 대해 페이징 된 리뷰 목록을 반환하기 위해 Response DTO 를 Page 객체로 한번 감싸서 반환하고 있습니다.
@GetMapping("/{classId}/reviews")
public ResponseEntity<SuccessResponse<Page<GetReviewResponse>>> getClassReviews(
@PathVariable Long classId,
@PageableDefault Pageable pageable
) {
return ResponseEntity.ok().body(
SuccessResponse.of(
ResponseMessage.REVIEW_GET_SUCCESS,
reviewService.getClassReviews(classId, pageable)
)
);
}
이렇게 Page 객체를 그대로 반환할 경우 , Postman 등으로 테스트를 해보면 다음과 같은 경고 메시지가 발생합니다.

2024-06-03 16:55:33.448 [http-nio-8080-exec-2] WARN org.springframework.data.web.config.SpringDataJacksonConfiguration$PageModule$PlainPageSerializationWarning - Serializing PageImpl instances as-is is not supported, meaning that there is no guarantee about the stability of the resulting JSON structure! For a stable JSON structure, please use Spring Data's PagedModel (globally via @EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO)) or Spring HATEOAS and Spring Data's PagedResourcesAssembler as documented in https://docs.spring.io/spring-data/commons/reference/repositories/core-extensions.html#core.web.pageables.
대략적인 뜻은, 다음과 같습니다.
PageImpl인스턴스를 그대로 직렬화하는 것은 지원되지 않으므로 반환하는 JSON 구조에 대한 안정성을 보장하지 않으니. 안정적인 JSON 구조를 위해 Spring Data의PagedModel이나Spring HATEOAS, Spring Data의PagedResourcesAssembler를 사용해주세요.
즉, 저는 Page 객체를 그대로 반환하고 있는데 PageImpl 클래스는 Page 인터페이스의 기본 구현체입니다. 이러한 PageImpl 인스턴스를 그대로 반환하지 말고, 제시하는 두 가지 방법 중 하나를 사용하여 반환하라 라는 말입니다.
그 이유에 대해서 위 링크의 공식 문서에서는 다음과 같이 설명하고 있습니다.
It’s common for Spring MVC controllers to try to ultimately render a representation of a Spring Data page to clients. While one could simply return
Pageinstances from handler methods to let Jackson render them as is, we strongly recommend against this as the underlying implementation classPageImplis a domain type. This means we might want or have to change its API for unrelated reasons, and such changes might alter the resulting JSON representation in a breaking way.
Spring Data Extensions :: Spring Data Commons
Page 인스턴스를 그대로 반환하는 것이 간단하게 Spring MVC 컨트롤러가 스프링 데이터 Page의 표현(representation)을 렌더링 하는 방법이지만, 이것을 강력하게 권장하지 않는다고 합니다.