Just Do IT!
[warning] Serializing PageImpl instances as-is is not supported 경고 발생 본문
[warning] Serializing PageImpl instances as-is is not supported 경고 발생
MOON달 2024. 10. 25. 12:06
PageModule$WarningLoggingModifier : 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. |
문제집 문제 전체 조회 관련 테스트를 진행하는데,
이렇게 조회가 된 이후에 warning이 떴다.
검색해보니
PageImpl 인스턴스를 직렬화할 때 JSON 구조의 안정성을 보장하지 못한다는 내용이며 Spring Data의 PageModel을 사용하는것을 권고하고 있다. 즉 페이지네이션을 적용할때 발생하는 문제였다.
Page 인터페이스의 직렬화 문제 때문에 새로 들어온 스펙이 있다고 한다.
https://github.com/spring-projects/spring-boot/pull/39797
Add a configuration property for Spring Data Web's serialization mode by quaff · Pull Request #39797 · spring-projects/spring-
see spring-projects/spring-data-commons@5dd7b32
github.com
여기 PR을 보면 자세하게 나와있다.
@EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO)
main 클래스에 이 어노테이션을 하나 추가하면 된다.
페이지 데이터를 DTO(Data Transfer Object)를 사용하여 안정적으로 JSON 구조를 형성하는 방법을 제공하는 어노테이션이다. 스프링 3.3에서 새로 추가되었다.
추가 전에는
이런 식으로 페이지네이션 관련 정보가 많이 나왔는데
어노테이션 추가 이후에는 이런 식으로 깔끔하게 나오는 걸 볼 수가 있다.
본 project에는 어노테이션을 추가했는데 혼자 기능 테스트 하는 프로젝트에는 추가하지 않았어서 겸사겸사 블로그에 정리해본다.