![[Spring] Serializing PageImpl instances as-is is not supported](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FeijekS%2FbtsPAAx0ywn%2FAAAAAAAAAAAAAAAAAAAAAGkKkUjMlUY5eB2tr8xkJ0Hu4ZhNS29SlBguTFHwbe6U%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1753973999%26allow_ip%3D%26allow_referer%3D%26signature%3Dd%252Bqa4U1dHrAi%252BMiQcggskH0Or0w%253D)
[Spring] Serializing PageImpl instances as-is is not supportedBack-End/기타2025. 7. 27. 20:25
Table of Contents
문제 상황
페이징 처리를 하던 도중 아래와 같은 오류가 발생하였다.
2025-07-27T20:08:49.993+09:00 WARN 34619 --- [ktsp] [nio-8080-exec-3] ration$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. |
Serializing PageImpl instances as-is is not supported
"PageImpl을 있는 그대로 JSON으로 직렬화하는 것은 지원되지 않으며 안정적이지 않다."
QueryDSL에서 PageImpl을 그대로 반환해서 생긴 오류였다.
즉, Spring이 제공하는 PageImpl 클래스는 직렬화 전용 DTO로 설계된 클래스가 아니며, 내부 필드 구조가 변경될 수 있기 때문에, 그것을 API 응답으로 내보내면 버전 업데이트 시 응답 구조가 바뀔 가능성이 생기기 때문에 경고가 발생하는 것이었다.
페이징 응답 구조도 다소 많고 복잡한것을 확인할 수 있다.
해결 방법
해결 방법은 간단하다.
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
이 애노테이션을 @Configuration이 있는 클래스나 @SpringBootApplication가 붙어있는 클래스(Main 클래스)에 붙혀주면 된다.
@SpringBootApplication
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
페이징 응답구조도 직관적이고 깔끔하게 변하였다.
참고
'Back-End > 기타' 카테고리의 다른 글
[Spring] Parameter 0 of constructor in xxx required a bean of type 'xxx' that could not be found. (0) | 2025.03.27 |
---|---|
[IntelliJ 오류] Web server failed to start. Port 8080 was already in use. (0) | 2024.03.02 |
[IntelliJ] 자주 사용하는 단축키 정리 (1) | 2024.01.24 |
IntelliJ에서 Database(MySQL, Oracle) 연결하기 (0) | 2024.01.09 |
IntelliJ Address localhost 1099 already in use 오류 해결 (0) | 2024.01.08 |