반응형
기존부터 사용하던 Pagenation인데 신규 플젝에서 이런 warn log가 발생했다.
알아보니 버전이 3.3 이상부터 이 로그가 나타나는것을 알게되었다. Page 인터페이스의 직렬화 문제 때문에 새로 생긴 스펙인듯 하다.
2025-01-12T00:18:53.046+09:00 WARN 12196 --- [nio-8080-exec-2] 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.
로그 해결 해소 방법

@EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO)
한 줄 첨부해서 로그가 나타나지 않도록 개선할 수 있다.
PageImpl 클래스는 사실 기본 생성자가 없는걸로 알고 있다. 역직렬화할 때 문제가 생길 수도 있고, 직렬화할 때 구조가 변형될 수도 있다. 예를 들면 필드 순서가 자꾸 바뀐다던지, 내부 구현 필드가 JSON에 노출되는 경우가 있다. 아래 변경 전 응답데이터를 보면 Spring Boot 2.x 에서는 못봤던 생소한 페이징 메타데이터들이 몇개 보인다. 이걸 방지하고 안정적인 구조를 유지하기 위해 페이지 직렬화 모드가 하나 더 추가된 듯 하다.
변경 전
{
"responseType": "SUCCESS",
"success": {
"content": [],
"pageable": {
"pageNumber": 0,
"pageSize": 10,
"sort": {
"empty": false,
"sorted": true,
"unsorted": false
},
"offset": 0,
"paged": true,
"unpaged": false
},
"last": true,
"totalPages": 0,
"totalElements": 0,
"size": 10,
"number": 0,
"sort": {
"empty": false,
"sorted": true,
"unsorted": false
},
"first": true,
"numberOfElements": 0,
"empty": true
}
}
변경 후
{
"responseType": "SUCCESS",
"success": {
"content": [],
"page": {
"size": 10,
"number": 0,
"totalElements": 0,
"totalPages": 0
}
}
}반응형
'Backend' 카테고리의 다른 글
| Spring 트랜잭션 내부 동작 원리 (0) | 2025.04.04 |
|---|---|
| [FCM] CI/CD github secret에서 json 파일 만들 때 유의할 점 (0) | 2025.01.16 |
| [Java] 일급 컬렉션 학습 내용 정리 (0) | 2025.01.06 |
| DDD 레이어드 아키텍처에 대한 고민 (0) | 2024.12.31 |
| Logback Rolling file appender 적용 (Docker volume mapping, Springboot ) (0) | 2024.12.30 |