I used the suggested approach in this question to return HATEOAS formatted outputs that match those returned by spring-data-rest. It works good, but is there a way to avoid boiler plate code to create entity resource assemblers like the QuestionResourceAssembler in the referenced question, if I only want to add 'self' links using the id to all entities? Perhaps using ResourceAssemblerSupport?
Asked
Active
Viewed 328 times
1 Answers
4
The easiest way is to simply use the Resource
wrapper type:
Resource<Person> personResource = new Resource<>(person);
personResource.addLink(…);
personResource.addLink(…);
Links can be created either by simply instantiating them (i.e. new Link("http://localhost/foo", "relation")
or by using the ControllerLinkBuilder
which allows you to point to Controller methods for obtain a reverse mapping. See this section of the Readme for details.

Oliver Drotbohm
- 80,157
- 18
- 225
- 211