No message body writer has been found for response class ArrayList

折月煮酒 提交于 2019-11-28 09:12:12

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;
}
Yazan Jaber

See this, Its JAXB thats giving you problems, it doesn't know how to unmarshal/marshal a List.

petrsyn

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

Dudi

To avoid the wrapping, one can use Jackson. On how to do it, you can follow my answer for a similar question.

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.

Try using the GenericEntity.

Response.ok(new GenericEntity<List<String>>(yourCollectionOfStrings) {}).build();
syam

Add this Maven dependency:

<init-param>
    <param-name>jaxrs.providers</param-name>
    <param-value>org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider</param-value>
</init-param>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!