My PageSort Entity,
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PageSort {
private String sortBy;
@SortValueConstraint
private String sortDirection;
}
My ProjectPage Entity
@Data
@RequiredArgsConstructor
@Validated
public class ProjectPage {
@Min(value = 1, message = "page number must be greater than zero")
@IsNumberValidatorConstraint(message = "page number must be numeric")
private String page = "1";
@Min(value = 1, message = "page size must be greater than zero")
@IsNumberValidatorConstraint(message = "page size must be numeric")
private String size = "25";
@Valid
private List<PageSort> sort = Arrays.asList(PageSort.builder().sortBy("id").sortDirection("asc").build());
}
My RestController class
@Validated
@RestController
@RequestMapping("/api/projects")
public class ProjectController extends AbstractCRUDController<Project, ProjectPostDTO, ProjectPatchDTO, ProjectResponseDTO> {
private ProjectApi projectApi;
@GetMapping
public ResponseEntity<ApiResponseDTO> getProjects(
@Valid ProjectPage projectPage,
@Valid ProjectSearchCriteria projectSearchCriteria){
return new ResponseEntity<ApiResponseDTO>(null, HttpStatus.OK);
}
}
I am trying to invoke the getProjects method as below
page and size parameter values are properly fetched inside the ProjectPage object but not the sort list in projectPage. But I tried using a single instance without the List and this worked perfectly.
Found a similar issue posted here Spring validation for RequestBody parameters bound to collections in Controller methods but did not solve the issue.
Any ideas on how to get this sorted?