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

Respect oneIndexedParameters property when serialising Page to JSON #3161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

clzola
Copy link

@clzola clzola commented Sep 23, 2024

I have noticed when using Spring Data in my project, I can set property spring.data.web.one-indexed-parameters to true and have my page numbering start from 1 in my API. However when returning Page from controller, this value is not respected and it will always return page number decreased by 1.

This PR fixes that by adding oneIndexedParameters attribute to SpringDataJacksonConfiguration.PageModule class. I have also added PageModuleCustomizer to be used to define wether PageModule will assume 1-based page number indexes in the request parameters

In order to respect this property, a PageModuleCustomizer needs to be defined:

@Bean 
public PageModuleCustomizer pageModuleCustomizer() {
    return pageModule -> {
        pageModule.setOneIndexedParameters(true); 
    }
}

Also this bean can be defined in Spring Boot Autoconfigure project, so spring will automatically take care of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants