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

OpenFeign client cannot correctly deserialize from stable page representation #1144

Open
fenuks opened this issue Jan 10, 2025 · 4 comments
Open
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@fenuks
Copy link

fenuks commented Jan 10, 2025

Describe the bug
I use new stable page representation format enabled with @EnableSpringDataWebSupport(pageSerializationMode = VIA_DTO).
When I try to download paged response from controller via feign client, page metadata isn't correctly parsed. Total elements number always equals number of elements in current page content (page content is parsed correctly). It seems that PageJacksonModule expects page metadata in the old format.

I'm using Spring Cloud v2024.0.0.

Sample
Sample project to reproduce this problem lives at
https://github.com/exempla/sb3_stable_page_feign_deserialization_problem. Run
mvn test to see the error.

@OlgaMaciaszek
Copy link
Collaborator

Thanks for reporting the issue, @fenuks. This would be a new enhancement. In general, we don't add enhancements to this project anymore, as it's in maintenance mode now (we suggest migrating over to Spring Interface Clients), but I think we may add support for this. However, I'm not sure when we'll be able to put this in the backlog, as maintenance-only projects have low priority. Feel free to submit a PR if you'd like it to be included faster.

@OlgaMaciaszek OlgaMaciaszek added enhancement New feature or request help wanted Extra attention is needed and removed in progress labels Jan 16, 2025
@fenuks
Copy link
Author

fenuks commented Jan 20, 2025

I could try to do that. It would be great if both page representations were supported at the same time, but I'm not sure if it is possible with current implementation based on Jackson module?

@OlgaMaciaszek
Copy link
Collaborator

@fenuks we need to support both. Could be using an opt-in flag for the new mode as the old mode hasn't been deprecated and is still in use. Then, in the next major release, we could swap the defaults.

@fenuks
Copy link
Author

fenuks commented Jan 21, 2025

Yes, I would like to support them both, but I wonder if we could support both without any flag.

Currently JacksonModule is being used and Jackson calls this constructor:

        SimplePageImpl(@JsonProperty("content") List<T> content,
@JsonProperty("pageable") Pageable pageable,
                @JsonProperty("number") @JsonAlias("pageNumber") int number,
                @JsonProperty("size") @JsonAlias("pageSize") int size,
                @JsonProperty("totalElements") @JsonAlias({ "total-elements",
"total_elements", "totalelements",
                        "TotalElements", "total" }) long totalElements,
                @JsonProperty("sort") Sort sort)

Fixing it to new representation is easy, one needs to rewrite it to

        SimplePageImpl(@JsonProperty("content") List<T> content,
                @JsonProperty("page") PagedModel.PageMetadata page),

Sorry for lack of clarity, what I was asking in previous post, is if we can support both page representations at the same time using JacksonModule or this mechanism is too limited to handle this? I know this could be done with new feign Decoder.

Say, I have feign client that consumes controller that for methods written pre-SB 3.0 still uses old page format for compatibility reasons, but all new methods use new stable format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants