我有一个通用的ServiceResponse类,如下所示:如何使用RESTEasy中的通用模板类(<T>)生成XML响应?
@XMLRootElement
public class ServiceResponse<T>
{
private T data;
private String error;
//setters n getters
}
从我的RESTEasy服务,我想生成XML响应为:
List<Customer> customers = someDAO.getCustomers();
ServiceResponse<List<Customer>> resp = new ServiceResponse<List<Customer>>();
resp.setData(customers);
resp.setError("No Error");
return resp;
or return Response.ok().entity(resp).build();
但这是抛出错误,因为是对Java没有JaxbMarshallWriter .util.List。
我可以列表列举usinig GenericEntity类。
GenericEntity<List<Customer>> entity = new GenericEntity<List<Customer>>(customers){};
Response.ok(entity).build();
但GenericEntity<ServiceResponse<List<Customer>>>
工作不说不JaxbMarshallWriter为java.util.List的。
是否有任何解决通用模板(,)的marshall/unmarshall类?
也许这有帮助吗? http://stackoverflow.com/questions/5391486/make-a-collection-generic-in-javax-xml-bind – Friso