Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No message body writer has been found for response class ArrayList

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

like image 982
aswininayak Avatar asked Feb 16 '12 12:02

aswininayak


People also ask

Is there a message body writer for response class folderlist?

No message body writer has been found for response class FolderList. I did not test every service but it looks like a problem across all of them.

Can CXF handle ArrayList's message body writer?

WARNING: No message body writer has been found for response class ArrayList. I know it's possible for CXF to handle this case because I've done it before - with a platform that defined the CXF and related maven artifacts behind the scenes (i.e.

Can CXF handle'no message body writer has been found'error?

I'm getting the following error: WARNING: No message body writer has been found for response class ArrayList. I know it's possible for CXF to handle this case because I've done it before - with a platform that defined the CXF and related maven artifacts behind the scenes (i.e.

Does OpenKM support the response class folderlist?

Open Source Document Management System | OpenKM - REST -> application/json -> No message body writer has been found for response class FolderList. REST -> application/json -> No message body writer has been found for response class FolderList.


2 Answers

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;
}
like image 81
Urs Reupke Avatar answered Oct 25 '22 11:10

Urs Reupke


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

like image 24
Yazan Jaber Avatar answered Oct 25 '22 11:10

Yazan Jaber