-
Notifications
You must be signed in to change notification settings - Fork 683
Spring Data Page doesn't serialize Sort to JSON correctly [DATACMNS-1244] #1683
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
Comments
Oliver Drotbohm commented
|
Oleg Danyliuk commented this format |
Oliver Drotbohm commented But why? This is a domain class. Just because you hand it to Jackson at it creates some representation from it, it doesn't mean we guarantee it. Never rely on the default representation generated from a class you don't control |
antonio-marrero commented It is a pity that in the Spring framework you need to tweak the JSON parser or create a DTO wrapper just to have a REST pagination with sorting. I think a default useful representation should be provided following the old Spring motto "convention over configuration" |
Oliver Drotbohm commented It's not about mottos, it's about separation of concerns |
antonio-marrero commented Good point (y) |
Ruslan Stelmachenko commented
I think the assumption comes from the fact that Page class was promoted by many guides as the class that controller can safely return. And many guides just return a default implementation of this class from controller, as returned by repository layer from spring-data. Page class even has a convenience method "map" for this use case to. spring-cloud-openfeign-core project also has a PageJacksonModule class, that "provides support to deserialize spring {
to deserialize a JSON into it's inner SimplePageImpl implementation. Obviously this will not work as intended when other side uses new spring-data because new PageImpl doesn't contain the "page" property. So, I understand that it's wrong to serialize a PageImpl and expect a stable JSON representation. But as you see even a "standard" project from Spring ecosystem (spring-cloud-openfeign-core) wrongly assumes this representation is stable. So, maybe this is not spring-data's responsibility, but if spring-boot (for example) can provide a default JSON representation for PageImpl in it's starter, it will be good thing, as many forget to think about this and wrongly "rely on the default representation generated from a class you don't control" |
Oleg Danyliuk opened DATACMNS-1244 and commented
This issue appeared in Spring-Data release 2. In latest version 1.13.9 (and older) it works fine.
Controller code:
Same for Spring-Data 2 style:
Configuration:
Also tried simple Spring application without Spring Boot with Java config as well as with XML config. Result is same:
If I change Spring-Data version to 1.X I'm getting correct JSON response for sorting object:
It seems I tried everything, I didn't find any notification on sort changes in changelog, I didn't find such issue in Spring JIRA.
So the question is how do I get with spring-data 2.X libs JSON with sorting like:
instead of:
Affects: 2.0.1 (Kay SR1), 2.0.2 (Kay SR2)
Reference URL: https://stackoverflow.com/questions/48263935/spring-data-page-doesnt-serialize-sort-to-json-correctly
Issue Links:
("is duplicated by")
1 votes, 5 watchers
The text was updated successfully, but these errors were encountered: