Is there a way to simplify the structure returned from this controller:
@GetMapping
public Iterable<Task> getAll(@PathParam("page") int page) {
Pageable pageable = PageRequest.of(page, 3);
return taskRepository.findAll(pageable);
}
Right now the body of the response is as follows:
localhost:8080/api/task?page=2
{
"content": [
...
],
"pageable": {
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"offset": 6,
"pageSize": 3,
"pageNumber": 2,
"paged": true,
"unpaged": false
},
"totalElements": 19,
"last": false,
"totalPages": 7,
"number": 2,
"size": 3,
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"numberOfElements": 3,
"first": false,
"empty": false
}
Is there any way to strip down on this data? What if I am not interested in sorting right now and only want to return something like this:
{
"content": [
...
],
"pageable": {
"pageSize": 3,
"pageNumber": 2,
"totalElements": 19,
},
}
So the current response just has too many properties I don't really need. What is a good way to achieve this? Should I be doing this completely differently if I want to customize it so much?