Java JPA、REST、解组元素列表
我的REST服务中有一个GET函数,它以XML格式返回对象列表Java JPA、REST、解组元素列表,java,rest,jaxb,jax-rs,Java,Rest,Jaxb,Jax Rs,我的REST服务中有一个GET函数,它以XML格式返回对象列表 @GET @Path("all") @Produces({"application/xml", "application/json"}) public List<Customer> findAll() { return getJpaController().findCustomerEntities(); } @GET @路径(“全部”) @产生({“application/xml”、“application/j
@GET
@Path("all")
@Produces({"application/xml", "application/json"})
public List<Customer> findAll() {
return getJpaController().findCustomerEntities();
}
@GET
@路径(“全部”)
@产生({“application/xml”、“application/json”})
公共列表findAll(){
返回getJpaController().findCustomerEntities();
}
如何将XML列表解组到对象列表?
我想将数据库中的所有这些客户存储到客户对象的一些列表或向量中
@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;
}
}
其中source
是任何输入流(文件、流)
其中source
是任何输入流(文件、流)
可能重复的可能重复似乎有效,但我不知道为什么我的列表总是空的。似乎有效,但我不知道为什么我的列表总是空的。
javax.xml.bind.JAXB.unmarshal(source, Response.class);
@GET
@Path("all")
@Produces({"application/xml", "application/json"})
public Response findAll() {
return new Response(getJpaController().findCustomerEntities());
}