Reputation: 2485
I have a GET function in my REST service that returns the list of objects in XML format.
@GET
@Path("all")
@Produces({"application/xml", "application/json"})
public List<Customer> findAll() {
return getJpaController().findCustomerEntities();
}
How can I unmarshall the list of XML to the list of objects? I would like to store all these customers from database into some List or Vector of Customers objects.
Upvotes: 1
Views: 608
Reputation: 29693
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Response
{
@XmlElement
private List<Customer> customers = new ArrayList<Customer>();
public Response(List<Customer> customers)
{
this.customers = customers;
}
public getCustomers()
{
return customers;
}
}
unmarshalling
javax.xml.bind.JAXB.unmarshal(source, Response.class);
where source
is any input stream (file, stream)
@GET
@Path("all")
@Produces({"application/xml", "application/json"})
public Response findAll() {
return new Response(getJpaController().findCustomerEntities());
}
Upvotes: 1