Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination from page 1 (one-indexed-parameters) not runs well #2889

Open
efimatica opened this issue Aug 1, 2023 · 4 comments
Open

Pagination from page 1 (one-indexed-parameters) not runs well #2889

efimatica opened this issue Aug 1, 2023 · 4 comments
Labels
status: feedback-provided Feedback has been provided

Comments

@efimatica
Copy link

Good morning from spain.
My scope is Spring boot 3.1 I'm implemeting REST service and I have pagination for return large list of elements. For default Spring boot manage the page from 0 index. I have reading that is possible start pagination from page 1, using this senetence in application.yaml:

spring:
  data:
    web:
      pageable:
        one-indexed-parameters: true

With new settings, the page 0 and the page 1 is the same. It show the same result. The problem is that the param "number" on paginations settings always show one page less, that I access:

Examples:

To page 0

Request: 
{{base_url}}/system/business/pagination?size=5&page=0

Response details:
    "pagination": {
    "totalPages": 4,
    "totalElements": 17,
    "size": 5,
    "number": 0,
    "numberOfElements": 5,
    "empty": false,
    "first": true,
    "last": false,
    "sorted": false
}

Note: I would prefer that it returns null. 

To page 1

Request: 
{{base_url}}/system/business/pagination?size=5&page=1

Response details:
    "pagination": {
    "totalPages": 4,
    "totalElements": 17,
    "size": 5,
    "number": 0,
    "numberOfElements": 5,
    "empty": false,
    "first": true,
    "last": false,
    "sorted": false
}

Note: Returns the same that page 0. See that number value is wrong. It would have to be 1. 

To page 2

Request: 
{{base_url}}/system/business/pagination?size=5&page=2

Response details:
    "pagination": {
    "totalPages": 4,
    "totalElements": 17,
    "size": 5,
    "number": 1,
    "numberOfElements": 5,
    "empty": false,
    "first": false,
    "last": false,
    "sorted": false
}

Note: Return the page 2, but number value is 1. 

Thanks for your attention

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 1, 2023
@odrotbohm
Copy link
Member

I suspect you serialize a Page instance? That is not supported (as discussed in #1683) in the sense that we do not guarantee the serialization format. What you essentially see is the internal structure of the Page implementation, un-adapted to the parameter resolution style you have configured. Jackson simply doesn't know about that customization.

To produce proper and stable JSON representations use PagedResourcesAssembler (via DI) and call toModel(Page).

@odrotbohm odrotbohm added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 1, 2023
@efimatica
Copy link
Author

Good morning,

Yes, I serialize the page instance, but I don't know if the problem lies there. When I use "one-indexed-parameters = true," the "number" value continues to use "zero-indexed-parameters." However, when "one-indexed-parameters = false," everything works well.

Regards,

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 2, 2023
@velykov
Copy link

velykov commented Jul 12, 2024

Same problem

@elijah-pl
Copy link

@odrotbohm

spring.data.web.pageable.serialization-mode=VIA_DTO changes nothing. The number field is always zero-indexed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided
Projects
None yet
Development

No branches or pull requests

5 participants