Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-1244

Spring Data Page doesn't serialize Sort to JSON correctly

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Works as Designed
    • Affects Version/s: 2.0.1 (Kay SR1), 2.0.2 (Kay SR2)
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      This issue appeared in Spring-Data release 2. In latest version 1.13.9 (and older) it works fine.

      Controller code:

      @RestController
      public class HelloController {
      
          @RequestMapping("/")
          public String index() {
              return "Greetings from Spring Boot!";
          }
      
          @RequestMapping(value = "sorttest", method = RequestMethod.GET)
          public Page<Integer> getDummy() {
              return new PageImpl<>(Collections.singletonList(1), new PageRequest(0, 5, new Sort("asdf")), 1);
          }
      
      }
      

      Same for Spring-Data 2 style:

      Pageable pageable = PageRequest.of(0, 10, new Sort(Sort.Direction.ASC, "asd"));
      PageImpl<Integer> page = new PageImpl<Integer>(Lists.newArrayList(1,2,3), pageable, 3);
      return page;
      

      Configuration:

      @SpringBootApplication
      @EnableWebMvc
      @EnableSpringDataWebSupport
      public class Application {
          public static void main(String[] args) {
              SpringApplication.run(Application.class, args);
          }
      }
      

      Also tried simple Spring application without Spring Boot with Java config as well as with XML config. Result is same:

      {
          "content": [
              1
          ],
          "pageable": {
              "sort": {
                  "sorted": true,
                  "unsorted": false
              },
              "offset": 0,
              "pageSize": 5,
              "pageNumber": 0,
              "paged": true,
              "unpaged": false
          },
          "totalElements": 1,
          "last": true,
          "totalPages": 1,
          "size": 5,
          "number": 0,
          "sort": {
              "sorted": true,
              "unsorted": false
          },
          "numberOfElements": 1,
          "first": true
      }
      

      If I change Spring-Data version to 1.X I'm getting correct JSON response for sorting object:

      {
          "content": [
              1
          ],
          "totalElements": 1,
          "totalPages": 1,
          "last": true,
          "size": 5,
          "number": 0,
          "sort": [
              {
                  "direction": "ASC",
                  "property": "asdf",
                  "ignoreCase": false,
                  "nullHandling": "NATIVE",
                  "ascending": true,
                  "descending": false
              }
          ],
          "numberOfElements": 1,
          "first": true
      }
      

      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:

      "sort": [
          {
              "direction": "ASC",
              "property": "asdf",
              "ignoreCase": false,
              "nullHandling": "NATIVE",
              "ascending": true,
              "descending": false
          }
      ]
      

      instead of:

      "sort": {
          "sorted": true,
          "unsorted": false
      }
      

        Attachments

          Activity

            People

            • Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              oleg.ig.danilyuk@gmail.com Oleg Danyliuk
              Last updater:
              Ruslan Stelmachenko
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: