I have several client classes sending a list of beans via PUT method to a jersey webservice, so I have decided to refactor them into one class using generics. My first attempt was this:
public void sendAll(T list,String webresource) throws ClientHandlerException {
WebResource ws = getWebResource(webresource);
String response = ws.put(String.class, new GenericEntity<T>(list) {});
}
But when I called it with:
WsClient<List<SystemInfo>> genclient = new WsClient<List<SystemInfo>>();
genclient.sendAll(systemInfoList, "/services/systemInfo");
It gives me this error:
com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.util.ArrayList, and MIME media type, application/xml, was not found
So I have tried taking out the method the GenericEntity declaration, and it works:
public void sendAll(T list,String webresource) throws ClientHandlerException {
WebResource ws = ws = getWebResource(webresource);
String response = ws.put(String.class, list);
}
Calling it with:
WsClient<GenericEntity<List<SystemInfo>>> genclient = new WsClient<GenericEntity<List<SystemInfo>>>();
GenericEntity<List<SystemInfo>> entity;
entity = new GenericEntity<List<SystemInfo>>(systemInfoList) {};
genclient.sendAll(entity, "/services/systemInfo");
So, why can't I generate a generic entity of a generic type inside the class, but doing it outside works?