While I am trying to return List its throwing No message body writer has been found for response class ArrayList.
I have code as follows:
@POST
@Pat
See this, Its JAXB thats giving you problems, it doesn't know how to unmarshal/marshal a List.
I have added the List to existing object of the project scope of domain layer.
It was more contextual for project and also worked out-of-the box: no needed to test XmlRootElement, but add the test data+logic for List of existing test case for that object.
To return a list, best wrap it into a container annotated @XmlRootElement
and give that container your list as a field, annotated as @XmlElement
.
Like so:
@XmlRootElement
public class Container {
@XmlElement
public List yourlist;
}
Add this Maven dependency:
<init-param>
<param-name>jaxrs.providers</param-name>
<param-value>org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider</param-value>
</init-param>
I've solved it using JacksonJaxbJsonProvider. No Java code needs to be modified. Just few changes in Spring context.xml
and Maven pom.xml
, see https://stackoverflow.com/a/30777172/1245231
To avoid the wrapping, one can use Jackson. On how to do it, you can follow my answer for a similar question.