Skip to content

Support for org.springframework.data.web.PageableDefault and org.springframework.data.web.SortDefault #4

Description

@lucaslm

It would be nice to be able to annotate the @RequestJsonApiPage parameter with either PageableDefault or SortDefault, and have custom defaults sort and pagination set for when those parameters lack. Something like

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping(value = "/app", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class RestController {
    @GetMapping
    public Response<Void> get(final @RequestJsonApiPage @PageableDefault(
        page = 0, size = 100,
        sort = {"id", "name"},
        direction = Sort.Direction.ASC
    ) Pageable page) throws Exception {
        return Response.<Void, Void>builder()
            .build();
    }
}

Or them:

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping(value = "/app", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class RestController {
    @GetMapping
    public Response<Void> get(
      @sortDefault(sort={"name", "age"}, direction=Sort.Direction.ASC)
      final @RequestJsonApiPage Pageable page) throws Exception {
        final Sort sort = page.getSort();
        // do anything with sort
        
        return Response.<Void, Void>builder()
            .build();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions