No message body writer has been found for response class ArrayList

aswininayak picture aswininayak · Feb 16, 2012 · Viewed 50.4k times · Source

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 
@Path("/{scope}/{application}/tables")
@Produces("application/xml")
public List<String> getTableNames(@PathParam("scope") String scope,
    @PathParam("application") String application, Request request) {

    // For example, I am returning a list of String
    return new ArrayList<String>(4);
}

Please help me. Thanks in advance

Answer

Urs Reupke picture Urs Reupke · Feb 16, 2012

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