-
Notifications
You must be signed in to change notification settings - Fork 474
Closed
Description
Hi all!!,
I´ve working with spring-hateoas and I have a Controller that returns both JSON and XML responses according to the response format requested.
When I return an entity object wrapped into a Resource in XML format, I can´t see my entity content in the response. However, when my entity extends ResourceSupport and is not wrapped into Resource, there´s no problem. When JSON response it works fine in every way.
For example:
When I return:
// stadium extends ResourceSupport and is annotated by @XmlRootElement
return new ResponseEntity<>(stadium, HttpStatus.CREATED);
That´s the response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<stadium>
<atom:link rel="self" href="http://localhost:8080/soccer/api/stadiums/1003" />
<name>Mestalla</name>
</stadium>
But the problem occurs when return:
// stadium does not extends ResourceSupport but has @XmlRootElement
Resource<Stadium> resource = new Resource<>(new Stadium("Mestalla"));
resource.add(/* whatever link*/);
return new ResponseEntity<>(resource, HttpStatus.CREATED);
That´s the response (No name tag. Root element is resource instead of stadium):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resource>
<atom:link rel="self" href="http://localhost:8080/soccer/api/stadiums/1003" />
</resource>
What I´m doing wrong?
Thanks and regards.
Metadata
Metadata
Assignees
Labels
No labels