Reputation: 1019
I'm trying to retrieve the list of documents from MongoDB using restful cxf webservice call. But I'm facing
No message body writer has been found for response in Class ArrayList.
I had followed this tutorial. Here they are returning employee object as a response in the CxfRestServiceImpl
class. So they had used @XMLElement(name = 'employee')
.
But now I'm trying to return list of documents from MongoDB as a response in the CxfRestServiceImpl
class. What changes I need to do in order to overcome this error?
Upvotes: 0
Views: 1391
Reputation: 21
You can "wrap" into Array like this
return Response.status(Response.Status.OK).entity(yourList.toArray(new YourObject[yourList.size()])).build();
where yourList is a List<yourObject>
or ArrayList<yourObject>
Upvotes: 2
Reputation: 39261
You can return a list of objects in your service. JAXB will do the conversion from ArrayList
@GET
@Path("/employees")
public List<Employee> getEmployees()
Ensure that the object has the JAXB XmlRootElement annotation.
@XmlRootElement(name="Employee")
public class Employee{
}
Upvotes: 0
Reputation: 914
If I understood you correct, You've got this exception in your code. Than, it is better for you to wrap your List answer in some other class.
@XmlRootElement(name="DocumentList")
public class DocumentList {
@XmlElement
public List<Document> documentList;
}
Upvotes: 2