How to remove the _embedded property in Spring HATEOAS
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In Spring HATEOAS, _embedded is the standard HAL field for collection resources, so it appears whenever you return CollectionModel with HAL media type. If you want to remove _embedded, you are changing the response format, not toggling a cosmetic option. The fix is to return a non HAL payload or create a custom wrapper that exposes items under your own field name.
Why _embedded Appears
HAL defines collection structure with two key sections:
_embeddedfor resource arrays._linksfor navigational links.
Spring HATEOAS follows this spec when your endpoint produces application/hal+json. For example, returning CollectionModel<EntityModel<UserDto>> will generate _embedded by design.
Option 1: Return Plain JSON Without HAL
If your consumers do not need HAL semantics, return a plain DTO list or wrapper and produce application/json.
This removes _embedded entirely because you are no longer using HAL collection serialization.
Option 2: Keep Links but Use a Custom Response Shape
Some teams want links but not HAL naming. In that case, avoid CollectionModel and define your own response object that includes items plus link fields.
This keeps discoverability while avoiding HAL reserved keys.
Option 3: Serve HAL and JSON on Different Endpoints
If some clients need HAL and others do not, expose content negotiation explicitly.
This is often the least disruptive migration path.
What Not to Do
Do not attempt random Jackson field filters directly on HAL output unless you fully own all clients and serializers. Removing _embedded from HAL while keeping the rest of HAL can break clients that expect spec compliant responses. If you must do custom serialization, treat it as a new media type and version it.
Testing Strategy
Add endpoint tests for both payload shape and content type. Verify:
application/jsonresponse containsitems, not_embedded.- HAL endpoint still includes
_embeddedfor compatibility. - Link names and URLs remain stable across refactors.
Migration Checklist
Before releasing a non HAL payload, confirm client expectations, API documentation, and contract tests are updated together. If external consumers depend on HAL, introduce a versioned endpoint instead of changing existing responses in place. This keeps integrations stable while you transition clients gradually.
Common Pitfalls
- Expecting
_embeddedremoval while still returning HALCollectionModel. - Mixing HAL and non HAL responses on the same endpoint without explicit media type handling.
- Changing payload shape without versioning or consumer communication.
- Returning links as raw strings with inconsistent relation names.
- Testing only status code and not serialized JSON shape.
Summary
_embeddedis part of HAL collection format, not a random Spring field.- Remove it by switching to non HAL JSON or custom response wrappers.
- Keep HAL endpoints when backward compatibility is required.
- Use explicit content types so clients know what format to expect.
- Add shape focused tests to prevent accidental response regressions.

