Spring-HATEOAS without extending ResourceSupport Spring-HATEOAS without extending ResourceSupport spring spring

Spring-HATEOAS without extending ResourceSupport


You can use the Resource wrapper:

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


You should separate Resources from your Domain.

Even if they might appear to be similar, Domain model and Resources are profoundly different.

Domain objects are your internal representation. The implementation have constraints depending on how your business logic/persistence is implemented and other design decision. For example they may be JPA entities or may be immutable.

Resources are the representation to the external world.Might be one-to-one with the Domain or totally different. It is not so infrequent having multiple Resource representation for a single Domain entity.

But first of all, the Resource implementation is meant to be sent/received on the wire. So it has constraints for being marashalled/unmarshalled.

So your application should have separate objects for the domain and the resources. With Spring HATEOAS the mapping is done using Resource assemblers.

You may have a look at this sample application: https://github.com/opencredo/spring-hateoas-sample and the related post: Implementing HAL hypermedia REST API using Spring HATEOAS