본문 바로가기
Spring

[Spring] 스프링 3.3에서 추가된 `pageSerializationMode = VIA_DTO`

by Nhahan 2024. 8. 26.

 

스프링 공식 Github 해당 스펙 PR 링크(https://github.com/spring-projects/spring-boot/pull/39797)

 

 


 

 

스프링 3.3으로 자료를 만들다가 처음 보는 WARN 로그가 보였다.

2024-08-26T15:13:27.588+09:00  WARN 63105 --- [todo] [nio-8080-exec-2] 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.

 


찾아보니까 Page 인터페이스의 직렬화 문제 때문에 새로 들어온 스펙이라고 한다.

config에 따로 빼는 것이 좋음

@EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO)

 

 

 

적용 전

{
    "totalPages": 5,
    "totalElements": 14,
    "number": 0,
    "sort": {
        "empty": true,
        "sorted": false,
        "unsorted": true
    },
    "first": true,
    "last": false,
    "size": 3,
    "content": [
        {
            "id": 14,
            "title": "asd55",
            "contents": "12312355",
            "commentCount": 0,
            "createdAt": "2024-08-26T15:03:39.517338",
            "modifiedAt": "2024-08-26T15:03:39.517338",
            "username": "가나ㅁㅁㅁ"
        },
        {
            "id": 13,
            "title": "asd55",
            "contents": "12312355",
            "commentCount": 0,
            "createdAt": "2024-08-26T15:03:37.939738",
            "modifiedAt": "2024-08-26T15:03:37.939738",
            "username": "가나"
        },
        {
            "id": 12,
            "title": "asd55",
            "contents": "12312355",
            "commentCount": 0,
            "createdAt": "2024-08-26T15:03:37.255681",
            "modifiedAt": "2024-08-26T15:03:37.255681",
            "username": "가나"
        }
    ],
    "numberOfElements": 3,
    "pageable": {
        "pageNumber": 0,
        "pageSize": 3,
        "sort": {
            "empty": true,
            "sorted": false,
            "unsorted": true
        },
        "offset": 0,
        "paged": true,
        "unpaged": false
    },
    "empty": false
}

 

 

 

적용 후

{
    "content": [
        {
            "id": 14,
            "title": "asd55",
            "contents": "12312355",
            "commentCount": 0,
            "createdAt": "2024-08-26T15:03:39.517338",
            "modifiedAt": "2024-08-26T15:03:39.517338",
            "username": "가나ㅁㅁㅁ"
        },
        {
            "id": 13,
            "title": "asd55",
            "contents": "12312355",
            "commentCount": 0,
            "createdAt": "2024-08-26T15:03:37.939738",
            "modifiedAt": "2024-08-26T15:03:37.939738",
            "username": "가나"
        },
        {
            "id": 12,
            "title": "asd55",
            "contents": "12312355",
            "commentCount": 0,
            "createdAt": "2024-08-26T15:03:37.255681",
            "modifiedAt": "2024-08-26T15:03:37.255681",
            "username": "가나"
        }
    ],
    "page": {
        "size": 3,
        "number": 0,
        "totalElements": 14,
        "totalPages": 5
    }
}

 

 

 

 

이런 차이가 있다.

 

 

댓글