Open joelkuiper opened 11 years ago
@joelkuiper I think your question is in correlation with my request: https://github.com/SpringSource/spring-data-rest/issues/85
May that be right?
Ah yes! Didn't see that request, seems to be essentially the same.
On Apr 15, 2013, at 8:43 PM, Johannes Hiemer notifications@github.com wrote:
@joelkuiper I think your question is in correlation with my request: #85
May that be right?
— Reply to this email directly or view it on GitHub.
@jhiemer Is it however currently possible to add a custom method to the search links which are exposed by default? I would assume that there would be a class I could overwrite or a ResourceProcessor I could add, but was unable to find a suitable one!
@joelkuiper me as well. The only way which is currently possible, as suggested by @olivergierke, is the creation of a Controller, which contains these specific custom methods. The only issue I have is, that I was not able to merge the mappings of SD REST and the manual mappings of Spring MVC.
Did you try that?
@jhiemer I was looking for an angle to do that, but haven't been very successful so far unfortunately
@joelkuiper I tried several things, but they did not work out. So far we are forced to wait on a reply of @jbrisbin.
The following ResourceProcessor
implementation will match the root Resource
:
@Bean
public ResourceProcessor<Resource<List>> rootLinksResourceProcessor() {
return new ResourceProcessor<Resource<List>>() {
@Override
public Resource<List> process(Resource<List> resource) {
resource.add(new Link("href", "rel"));
return resource;
}
};
}
Notice that this is a naive approach. By that I mean I'm not interrogating the Resource to determine what kind of Links are being returned. This signature will match any Resource<List>
being returned. That may not always be desired.
It would be possible for SDR to subclass Resource
and return a specific type of resource for each return. I haven't thought through the side effects of that (if there are any) but I think that would be relatively low-risk.
I added a special subclass for Resource
that's returned on listing repositories. In the example submodule config you can see how to set up a ResourceProcessor
that adds links.
Hey all,
I'm trying to add a custom link to the repository URL but so far I've been unsuccessful.
Currently I have a custom query in my Repository (using the standard Spring data JPA method of extending single repositories) but now I'd like to expose that query method from within the repository with a HATEOAS link.
For example:
I know you can add a ResourceProcessor<Resource<?>> to add links to a Resource, but is there a similar construct for the repositories themselves?