-
Notifications
You must be signed in to change notification settings - Fork 678
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
Unpaged
instances not Jackson-serializable out of the box
#2987
Comments
similar issue, my error message is:
|
You can return a
|
I have the same issue. All of my mockMvc tests are affected where
|
Our domain objects such as |
Explaination why this fails: If you instanciate PageImpl without Pageable it uses the "Unpaged" isnatnce.
Now unpaged is an Object, and jackson tries to seralize all the fields. My solution unitl SpringBoot offers a better way to return pages: Instanciate PageImpl with Pageable as parameter (Of course only in tests):
|
The unpaged object is represented by an enum. As this is an implementation detail, Jackson tends to apply its enum serialization. |
In the newest version it is no more an enum
Thats why there errors come up now |
my workaround to this issue (using custom |
I've solved my tests changing by |
We're looking into this evaluating different strategies to mitigate the issue. |
Good morning, I am facing the same error. |
Adding Pageable to all our tests solved this for us. We do not have use cases where we request a Page without a pageable FYI. |
Hello @bjornharvold, |
We now reinstantiate the serialization of Unpaged instances as plain INSTANCE strings as they were rendered before Unpaged was changed from an enum into a class. Note, that we still strongly advise, not to serialize Page instances directly as it's a domain type, its Jackson-level surface is subject to change if we need to change the type's API for unrelated reasons.
We now reinstantiate the serialization of Unpaged instances as plain INSTANCE strings as they were rendered before Unpaged was changed from an enum into a class. Note, that we still strongly advise, not to serialize Page instances directly as it's a domain type, its Jackson-level surface is subject to change if we need to change the type's API for unrelated reasons.
…tly. We now issue a one-time warning log if Jackson gets handed a PageImpl to serialize as the Jackson structure might need to change for arbitrary other reasons.
The serialization of Accepting that having to use Spring HATEOAS might be a bit of a tough burden, we're currently looking into options to allow creating the kind of same representation but not add the page navigation elements via links as that's what both requires Spring HATEOAS and deciding on a hypermedia enabled media type. |
Unpaged
instances not Jackson-serializable out of the box
We now reinstantiate the serialization of Unpaged instances as plain INSTANCE strings as they were rendered before Unpaged was changed from an enum into a class. Note, that we still strongly advise, not to serialize Page instances directly as it's a domain type, its Jackson-level surface is subject to change if we need to change the type's API for unrelated reasons. Fixes: GH-2987.
We now issue a one-time warning log if Jackson gets handed a PageImpl to serialize as the Jackson structure might need to change for arbitrary other reasons. Fixes GH-2987.
For those who are still looking for the fix. We are using Spring Boot 3.2.4. Adding the SpringDataJacksonConfiguration.PageModule to the Jackson2ObjectMapperBuilder solved the Problem. SpringDataJacksonConfiguration.PageModule comes from spring-data-commons-3.2.4
|
Shouldn't all beans implementing Jackson |
- Fix the warning about PageImpl (see spring-projects/spring-data-commons#2987). - Do not call repositories directly from controllers. - Cleanup TaskListEntity.
Hi,
after upgrading to spring boot 3.2.0, some unit tests failed with the error:
Here is the test:
If I replace
doReturn(Page.empty()).when(activityLogService).findAll(any(Predicate.class),any(Pageable.class),any());
with
doReturn(Page.empty(PageRequest.of(1, 10, Sort.by("id")))).when(activityLogService).findAll(any(Predicate.class),any(Pageable.class),any());
the error is gone.
It seems
Page.empty()
is not serializable whilePage.empty(PageRequest.of(1, 10, Sort.by("id")))
is.Is it a regression or did I miss something ?
The text was updated successfully, but these errors were encountered: