I've been scouring the docs and the Restbucks implementation by Oliver but I don't seem to be able to configure the links on a generated Spring REST repository resource. (I can add to them, but cannot remove them via the ResourceProcessor as the processor is invoked prior to conversion by the looks of things)
My case is quite simple and that is I wish to omit rel links on objects that point to null or an empty collections (such as in the case of say a graph node parent/child structure)
Would anybody have any incite as to how I could achieve this? Ideally I would like to have something suggested in the Restbucks README (but I cannot find it used) where a custom RestResourceEntityLinks extension would be picked up and links generated from said implementation as my case applies to all domain objects.
But perhaps there is an easier way that I am yet to come across? Or perhaps having these links point to an empty array or null is a valid hateoas ref so I should just leave it be and move on?
Thanks in advance
Generally speaking you should be able to remove links by just calling Resource.getLinks()
and mess with the List
returned. If you think a Resource.removeLink(String rel)
makes sense, feel free to create a ticket for that.
However, I'd argue the links pointing to empty resources makes sense as the presence of links has an important role in telling the client that there's a related resource it can interact with. In other words: if the link is not available, how would the client find out about the possibility to assign a related resource, or to add an element to the currently empty collection.
Links are not only representing the current state of the resource but affordances to what the client shall/can do next. Take the payment
link in the RESTBucks project for example. It's only present, if no payment has been placed yet. Once done, the link even disappears. That's actually the opposite of what you're shooting for :).
来源:https://stackoverflow.com/questions/24507336/spring-data-rest-ref-link-omission-when-null-or-empty