Formatting spring-data-rest / spring -hateoas mirrors in custom controllers
I used the suggested approach in this question to return HATEOAS formatted output that matches the one returned by spring-data-rest. It works well, but is there a way to avoid the tabular code to create entity resource assemblers like QuestionResourceAssembler in the referenced question if I only want to add "native" references using an id for all objects? Perhaps using ResourceAssemblerSupport ?
source to share
The easiest way is to just use the shell type Resource
:
Resource<Person> personResource = new Resource<>(person);
personResource.addLink(…);
personResource.addLink(…);
Links can be created either by simply creating them (i.e. new Link("http://localhost/foo", "relation")
, or using ControllerLinkBuilder
), which allows you to specify controller methods to get the reverse mapping. See this section of the Readme for details.
source to share