Fix #1324: Add @JsonAlias support to SimplePageable for SNAKE_CASE compatibility#1331
Open
weslyvinicius wants to merge 3 commits intospring-cloud:4.3.xfrom
Open
Conversation
…NAKE_CASE compatibility Signed-off-by: weslyvinicius <weslyvinicius@hotmail.com>
…NAKE_CASE compatibility Signed-off-by: weslyvinicius <weslyvinicius@hotmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #1324 by adding @JsonAlias support to the SimplePageable class in PageJacksonModule, enabling proper deserialization of Spring Data Page objects when a global Jackson PropertyNamingStrategy (such as SNAKE_CASE) is configured. Previously, the hardcoded @JsonProperty annotations with camelCase names conflicted with global naming strategies, causing deserialization failures.
Changes:
- Added
@JsonAliasannotations toSimplePageableconstructor parameters to support multiple naming conventions (snake_case, kebab-case, lowercase, PascalCase) - Added comprehensive test coverage with 4 new test methods and JSON fixtures for different naming strategies
- Maintains backward compatibility by keeping camelCase as the primary
@JsonPropertyvalue
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageJacksonModule.java | Added @JsonAlias annotations to SimplePageable constructor parameters for pageNumber and pageSize to support multiple naming conventions |
| spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/PageJacksonModuleTests.java | Added 4 test methods to verify deserialization with different PropertyNamingStrategies (KEBAB_CASE, SNAKE_CASE, LOWER_CASE, UPPER_CAMEL_CASE) |
| spring-cloud-openfeign-core/src/test/resources/withPageableAliasHyphen.json | Test fixture with kebab-case naming (page-number, page-size) |
| spring-cloud-openfeign-core/src/test/resources/withPageableAliasUnderscore.json | Test fixture with snake_case naming (page_number, page_size) |
| spring-cloud-openfeign-core/src/test/resources/withPageableAliasLowercase.json | Test fixture with lowercase naming (pagenumber, pagesize) |
| spring-cloud-openfeign-core/src/test/resources/withPageableAliasPascalCase.json | Test fixture with PascalCase naming (PageNumber, PageSize) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...n-core/src/test/java/org/springframework/cloud/openfeign/support/PageJacksonModuleTests.java
Outdated
Show resolved
Hide resolved
Signed-off-by: weslyvinicius <weslyvinicius@hotmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1324
When a global PropertyNamingStrategies.SNAKE_CASE is configured, deserialization of Page fails because SimplePageable only accepted camelCase property names.
This PR adds @JsonProperty + @JsonAlias to the constructor parameters, supporting:
pageNumber / page_number / page-number / pagenumber
pageSize / page_size / page-size / pagesize
Tested with the reproduction case provided in the issue (global SNAKE_CASE + WireMock returning snake_case JSON).