Search code examples
springrestspring-mvchateoasspring-hateoas

Spring-HATEOAS without extending ResourceSupport


I'm building a REST API. I have a domain model composed of beans than can't extend ResourceSupport. Which is the best way to expose them as resources using Spring-HATEOAS?

In case that's not possible, which is the best way to include links on the JSON generated by the beans?


Solution

  • You can use the Resource wrapper:

    MyModel model = ...
    Resource<MyModel> resource = new Resource(model);
    resource.add(linkTo(...