question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Option to remove _embedded from CollectionModel

See original GitHub issue

Today, when returning a CollectionModel from any resource, it seems impossible to render it without _embedded. It’s possible to disable the deserializer though, but it makes the field to be rendered as content instead of _embedded.

The purpose of this feature request would be, then, to wrap the elements in the content field at all, and at the same time rendering the links field as usual.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
gregturncommented, Mar 9, 2020

The _embedded attribute is a requirement for collection when you render HAL.

If you’re trying to get away from HAL, the simplest thing could be rendering directly, using Jackson, our types (CollectionModel, EntityModel, etc.).

That’s easy if you just register your own mediatype. Here’s an example:

@Bean
HypermediaMappingInformation antiqueMedia() {
	return new HypermediaMappingInformation() {
		@Override
		public List<MediaType> getMediaTypes() {
			return Arrays.asList(MediaType.parseMediaType("application/antique+json"));
		}
	};
}

This will register another mediatype, and basically clone the Jackson ObjectMapper, but without registering any special serializers. If you wish to register your own handlers for those types, look into the rest of the HypermediaMappingInformation SPI.

That would yield:

{
  "links": [
    {
      "rel": "self",
      "href": "http://localhost:8080/employees"
    }
  ],
  "content": [
    {
      "name": "Frodo Baggins",
      "role": "ring bearer",
      "links": [
        {
          "rel": "self",
          "href": "http://localhost:8080/employees/0"
        },
        {
          "rel": "employees",
          "href": "http://localhost:8080/employees"
        }
      ]
    },
    {
      "name": "Bilbo Baggins",
      "role": "burglar",
      "links": [
        {
          "rel": "self",
          "href": "http://localhost:8080/employees/1"
        },
        {
          "rel": "employees",
          "href": "http://localhost:8080/employees"
        }
      ]
    }
  ]
}
0reactions
odrotbohmcommented, Mar 9, 2020

I’ve commented on the StackOverflow question.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove the "_embedded" property in Spring HATEOAS
I close HAL feature, because it is hard to using Resources/Resource by restTemplate. I disable this feature by following code:
Read more >
Spring HATEOAS - Reference Documentation
The representation can be enriched by a variety of embedded documents, which can be either arbitrary objects or HAL representations themselves ( ...
Read more >
spring-projects/spring-hateoas - Gitter
Hi! I've got a little typing problem here. I got a WebTestClient and I use the kotlin extension for .returnResult<CollectionModel<AssignmentConfigurationModel>> ...
Read more >
Remove _embedded in HATEOAS link using spring-boot-2.2 ...
I was able to remove the _embedded attribute by passing false as an argument to useHalAsDefaultJsonMediaType method in RepositoryRestConfiguration class.
Read more >
How to Build Hypermedia API with Spring HATEOAS - Grape Up
We use HTTP methods instead of verbs describing actions, e.g., DELETE method instead of ... We can get a similar result when requesting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found