In a Spring-Web RestController we use PagedResources
to create ResponseEntities.
We have a RequestMethod that will trigger a background search for Elements in a 5km radius, if theres no result in 10km, 20km, until we find any Element.
Since we now alter the given Options from the Client (the Resource is called with a given distance), we want to give the altered searchDistance back to the Client. The actual Response then will be something like this:
{
"_links": {
"self": {
"href": "http://...
"templated": true
}
},
"_embedded": {
"parcelShopResourceList": [
{
"_id": "2760183530"
...
},
{
"_id": "2760128505"
...
},
{
"_id": "2760162267"
...
},
{
"_id": "2760196914"
...
},
{
"_id": "2760147255"
...
}
]
},
"page": {
"size": 200,
"totalElements": 5,
"totalPages": 1,
"number": 0
"searchDistance": 10
}
}
Now the Question:
- How can i extend
PagedResourcesAssembler
, so it will return any additional Page Informations?
I thought it would be enough to create an extended Page
, so PagedResourcesAssembler
will add the extra information to the page informations, but this was not the case.
ResponseEntity.ok(pagedResourcesAssembler.toResource(page, resourceAssembler));
I then tried to override the PagedResourcesAssembler
itself, but since it uses a lot of private Methods the Override of PagedResourcesAssembler.createResource
is not really usefull.
I think i am missing something completely. Can please anyone explain to me how i can add additional Information in my Response? I am sure there is a much more easy way for this.
Since i want to add an information that regards the whole List, i do not want to insert this information into a single resource just for convenience.