Hello,
I'm relatively new to jaxrs, jersey and rest web service implementations in
general so this is probably a very easy question to answer.
I'm using jersey to return a collection of objects to the consumer of the
service using the response.getEntity(classname) as depicted below. I have
two classes ChartDataWrapper and EnvFromHourly, depicted below.
My Question would be how can I return just a List of EnvFromhourly objects
using the Response object? I get a write exception when I try
Response.ok(ArrayList of EnvFromHourly objects).build(); I created
ChartDataWrapper to hold a List of EnvFromHourly and then I do a
Response.ok(ChartDataWrapper).build(); and that works, but I'm looking for a
more efficient way
EnvFromHourly:
@XmlRootElement(name="EnvFromHourly")
public class EnvFromHourly implements Serializable
{
//variables and getters/setters
}
EnvFromHourly:
@XmlRootElement(name="ChartDataWrapper")
public class ChartDataWrapper implements Serializable
{
private List<?> items;
public List<?> getItems() {
return items;
}
public void setItems(List<?> items) {
this.items = items;
}
}
Service Method:
@POST
@Path(TOP_SPAM_SENDER_DATA)
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getTopSpamSenderData(TopSpamSenderChart chart) throws
Exception {
//getTopSpamSender just returns a populated ChartDataWrapper object
return Response.ok(getTopSpamSender(chart)).build();
}
Service client code:
Client client = Client.create();
WebResource webResource = client.resource(ChartUtils.getURL() +
BASE_RESOURCE_LOCATION);
ClientResponse response =
webResource.path(TOP_SPAM_SENDER_DATA).type(MediaType.APPLICATION_XML).post(ClientResponse.class,
chart);
ChartDataWrapper wrapper = response.getEntity(ChartDataWrapper.class);
--
View this message in context: http://n2.nabble.com/javax-xml-bind-JAXBException-when-building-Response-tp4248580p4248580.html
Sent from the Jersey mailing list archive at Nabble.com.