Controller returns ResponseEntity
@GetMapping("/users/{id}")
public ResponseEntity<UserResource> getUserById{}
User resource is extended from RestResource
public class UserResource extends ResourceSupport {}
When I call the rest API, I get
{
"user": {
"id": 49,
"firstName": "Admin"
},
"links": [
{...}]
}
How do I get it without the top level wrapped? like this?
{
"id": 49,
"firstName": "Admin"
}
It's interesting because when I use Spring Data Rest, the data returned is actually the latter kind but SDR also uses Spring-HATEOAS.
You do not need to create a
ResponseEntity. Simply return the object:If you wanna use HATEOAS, I afraid there is no way to have your payload in the root (without wrapping). But you also can return the object without the
ResponseEntity: https://www.baeldung.com/spring-hateoas-tutorial