How to embedd Resources in RepresentationModel with own Properties
03:16 13 Mar 2026

I'm new to Spring HATEOAS and I hope I'm just missing something really obvious here.

I know that EntityModel wraps a single POJO, so I can add _links to it.

I know that CollectionModel wraps multiple POJOS and puts them into the _embedded portion of a HAL-Resource.

From what I've read in the Spec-Teaser, it's also possible to have a state, links and _embedded in a Resource.

However I haven't been able to find a way to actually create a Representation in Spring HATEOAS that ends up looking like the one in mentioned page (CURIES and templating aside):

{
    "_links": {
        "self": { "href": "/orders" },
        "curies": [{ "name": "ea", "href": "http://example.com/docs/rels/{rel}", "templated": true }],
        "next": { "href": "/orders?page=2" },
        "ea:find": {
            "href": "/orders{?id}",
            "templated": true
        },
        "ea:admin": [{
            "href": "/admins/2",
            "title": "Fred"
        }, {
            "href": "/admins/5",
            "title": "Kate"
        }]
    },
    "currentlyProcessing": 14,
    "shippedToday": 20,
    "_embedded": {
        "ea:order": [{
            "_links": {
                "self": { "href": "/orders/123" },
                "ea:basket": { "href": "/baskets/98712" },
                "ea:customer": { "href": "/customers/7809" }
            },
            "total": 30.00,
            "currency": "USD",
            "status": "shipped"
        }, {
            "_links": {
                "self": { "href": "/orders/124" },
                "ea:basket": { "href": "/baskets/97213" },
                "ea:customer": { "href": "/customers/12369" }
            },
            "total": 20.00,
            "currency": "USD",
            "status": "processing"
        }]
    }
}

I know I can extend RepresentationModel to create a representation with custom properties, but if I add a CollectionModel as a property, it's not in _embedded , but in the variable name I set.

Of course it would be a solution to create a record class that saves just the list (with the name in collectionRelation) and save that record in my extended class under _embedded, but is that really the solution, to create two extra classes just to have the same functionality that CollectionModel provides out of the box and that should already be implemented via the HAL-Spec?

Would love hints on where I've missed something!

spring-hateoas