First at all I read the previous question: Exposing link on collection entity in spring data REST
But the issue still persist without trick.
Indeed if I want to expose a link for a collections resources I'm using the following code:
@Component
public class FooProcessor implements ResourceProcessor<PagedResources<Resource<Foo>>> {
private final FooLinks fooLinks;
@Inject
public FooProcessor(FooLinks fooLinks) {
this.FooLinks = fooLinks;
}
@Override
public PagedResources<Resource<Foo>> process(PagedResources<Resource<Foo>> resource) {
resource.add(fooLinks.getMyCustomLink());
return resource;
}
}
That works correctly except when collection is empty...
The only way to works is to replace my following code by:
@Component
public class FooProcessor implements ResourceProcessor<PagedResources> {
private final FooLinks fooLinks;
@Inject
public FooProcessor(FooLinks fooLinks) {
this.FooLinks = fooLinks;
}
@Override
public PagedResources process(PagedResources resource) {
resource.add(fooLinks.getMyCustomLink());
return resource;
}
}
But by doing that the link will be exposed for all collections.
I can create condition for exposing only for what I want but I don't think is clean.