EntityModel is the Spring HATEOAS class that wraps a single domain object and attaches hypermedia links to it. Instead of returning bare JSON, your REST endpoint returns the data plus links such as self, orders or delete, so a client can discover what it may do next without hard-coding URLs.
It lives in the org.springframework.hateoas package and extends RepresentationModel. In Spring Boot 3 (Spring HATEOAS 2.x) the default media type is HAL, so the wrapped object is rendered together with a _links section.
HATEOAS (Hypermedia as the Engine of Application State) is the part of REST where responses describe the available next steps. Spring HATEOAS models this with three main types:
| Type | Represents | Typical use |
|---|---|---|
RepresentationModel | Links only, base class | Custom representations that extend it |
EntityModel<T> | One resource of type T plus links | Response for GET /products/42 |
CollectionModel<T> | A collection of items plus links | Response for GET /products |
PagedModel<T> | A page of items plus paging metadata and links | Paginated listings |
EntityModel<T> keeps your domain object (getContent()) separate from the links (getLinks()), so you do not have to change the entity class itself to make it hypermedia-aware.
With Spring Boot, add the starter. It brings in Spring HATEOAS and enables HAL rendering automatically.
Create the model with EntityModel.of(...) and build links with WebMvcLinkBuilder. Using methodOn(...) means the link is generated from the real controller mapping, so renaming a path does not leave stale URLs behind.
A request to GET /products/42 then returns a HAL document similar to this:
The domain fields are flattened next to _links, because HAL renders the content of an EntityModel inline.
Repeating link code in every method gets noisy. A RepresentationModelAssembler converts a domain object into its EntityModel in one place and can also build the whole collection.
The controller injects the assembler and calls assembler.toModel(product) or assembler.toCollectionModel(products). This keeps controllers short and guarantees every representation of a product carries the same links.
Links are most useful when they change with the resource state. An order that is already shipped should not offer a cancel link, so the client never has to guess:
The client reads the presence of cancel in _links instead of duplicating the business rule in its own code.
EntityModel but forgetting spring-boot-starter-hateoas, which leaves you without HAL rendering and the Accept: application/hal+json handling.linkTo(methodOn(...)), which breaks when mappings or the context path change.EntityModel inside your service or persistence layer. It is a web representation and belongs in the controller or assembler.Resource and Resources names. They were renamed to EntityModel and CollectionModel in Spring HATEOAS 1.0.RepresentationModel only holds links and is meant to be extended. EntityModel<T> is a ready-made subclass that wraps any object of type T, so you do not have to change your domain class.
Yes. Resource was renamed to EntityModel in Spring HATEOAS 1.0, and Resources became CollectionModel. The behaviour is the same, but the package and some factory methods changed.
Yes. Use WebFluxLinkBuilder to build links in reactive controllers and return Mono<EntityModel<T>>.
No. It pays off for public or long-lived APIs where clients should follow links. For simple internal JSON APIs, plain DTOs are usually enough.
EntityModel<T> wraps one resource together with its hypermedia links. Build the links with linkTo(methodOn(...)), centralise the mapping in a RepresentationModelAssembler, and use CollectionModel and PagedModel for lists. In Spring Boot 3 the response is rendered as HAL by default, so clients receive the data plus a _links section they can follow.