I am trying to make a web service with Jax-RS (using the Glassfish 3.1.1, all RI). The Question class is annotated with @XmlRootElement and have this method. I have not annotated it with any Jax-RS annotations. What I expected was that you would get one answers-element that had all the answer-elements inside...but that is not the case obviously. How do I that? The Answer class is also annotated with @XmlRootElement.
@OneToMany(cascade = CascadeType.ALL)
public List<Answer> getAnswers() {
return answers;
}
This is the response:
<questions>
<question>
<answers>
<correct>true</correct>
<description>Answer one</description>
<id>1</id>
</answers>
<answers>
<correct>false</correct>
<description>Answer two</description>
<id>2</id>
</answers>
<description>Question One</description>
<id>1</id>
<imageName>hello.png</imageName>
<status>SUBMITTED</status>
</question>
...
</questions>