I have a working json service which looks like this:
@POST
@Path(\"/{id}/query\")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(JSON)
public ListWrapper qu
If your web-service produces a JSON you must handle that in your client by using an accept()
method:
ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).post(searchQuery, MediaType.APPLICATION_JSON);
ListWrapper listWrapper = response.getEntity(ListWrapper.class);
Try this and give your results.
The WebResource.entity(...) method doesn't alter your webResource instance... it creates and returns a Builder object that holds the change. Your call to .post is typically performed from a Builder object rather than from the WebResource object. That transition is easily obscured when all the requests are chained together.
public void sendExample(Example example) {
WebResource webResource = this.client.resource(this.url);
Builder builder = webResource.type(MediaType.APPLICATION_JSON);
builder.accept(MediaType.APPLICATION_JSON);
builder.post(Example.class, example);
return;
}
Here's the same example using chaining. It's still using a Builder, but less obviously.
public void sendExample(Example example) {
WebResource webResource = this.client.resource(this.url);
webResource.type(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.post(Example.class, example);
return;
}