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

Spring Boot 3.2.4 (Cloud 2023.0.1) Cannot deserialize "pageable": "INSTANCE" #1018

Closed
dienarvil opened this issue Apr 8, 2024 · 5 comments
Closed
Labels
question Further information is requested

Comments

@dienarvil
Copy link

dienarvil commented Apr 8, 2024

Describe the bug

Rest Controller in server with Spring Boot 2.7.18:

image

If I consume that end point from application with Spring Boot 2.7.18 (Cloud 2021.0.5) Deserialization is correct.

If I consume that end point from application with Spring Boot 3.2.4 (Cloud 2023.0.1) Deserialization fails.

log trace:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of org.springframework.cloud.openfeign.support.PageJacksonModule$SimplePageable (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('INSTANCE')


If I create Page object with the constructor:

Page page = new PageImpl<>(build, PageRequest.of(0,2), 2);

Works perfectly in Spring 2.7.18 and Spring boot 3.2.4

Thank you !!

@dienarvil dienarvil changed the title Spring Boot 2.3.4 (Cloud 2023.0.1) Cannot deserialize "pageable": "INSTANCE" Spring Boot 3.2.4 (Cloud 2023.0.1) Cannot deserialize "pageable": "INSTANCE" Apr 8, 2024
@OlgaMaciaszek
Copy link
Collaborator

Hello @dienarvil, thanks for reporting the issue. Please provide a minimal, complete, verifiable example that reproduces the issue.

@dienarvil
Copy link
Author

demo.zip

localhost:8080/testok -> feign call to ok end point with Page page = new PageImpl<>(build, PageRequest.of(0,2), 2);
and
localhost:8080/testko -> feign call to ko end point with Page page = new PageImpl<>(build, Pageable.unpaged(), 2);

@ttddyy
Copy link

ttddyy commented Apr 14, 2024

I just stumbled upon the same symptom and dug in a bit.

The reported error happens when deserializing the following json:

{
  "content": [
    "foo"
  ],
  "pageable": "INSTANCE",   <== HERE
  "totalPages": 1,
  "totalElements": 1,
  "last": true,
  "size": 1,
  "number": 0,
  "sort": [],
  "numberOfElements": 1,
  "first": true,
  "empty": false
}

As @dienarvil noted, the json is generated by the following:

Page<String> page = new PageImpl<>(List.of("foo"));  // or usage of Pageable.unpaged()
String json = this.objectMapper.writeValueAsString(page);

// deserialize json will throw the exception

When serializing a PageImpl, if it doesn't specify the pageable parameter, it uses Pageable.unpaged().
SpringDataJacksonConfiguration from spring-data-commons registers a serializer for Unpaged which writes out the value INSTANCE. So, the generated json has pageable:"INSTANCE".

It is not the json format that spring-cloud-openfeign is expecting.
In v4.1.1, PageJacksonModule#SimplePageImpl added Pageable object parameter(#984) and the expected format is SimplePageable. The deserializer doesn't work for INSTANCE string from Unpaged.

Per spring-projects/spring-data-commons#3024, spring-data-commons v3.3 may produce a more stable json representation.

@dienarvil
For a fix, I suggest simply providing the page information(Pageable) rather than using Unpaged while creating PageImpl object. So, that the response json will be more conformed as an added benefit.

@dienarvil
Copy link
Author

@dienarvil For a fix, I suggest simply providing the page information(Pageable) rather than using Unpaged while creating PageImpl object. So, that the response json will be more conformed as an added benefit.

Thanks for the advice, yeah, with "normal" pagination from a repository the problem will never arise.

Thanks again!!

@OlgaMaciaszek
Copy link
Collaborator

Thanks for the analysis @ttddyy. Until this gets addressed better in Spring Data, we expect a proper Pageable object to be provided.

@OlgaMaciaszek OlgaMaciaszek added question Further information is requested and removed feedback-provided labels Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants