user2657714 user2657714 - 9 months ago 80
JSON Question

Read response body in JAX-RS client from a post request

Having some sort of proxy between a mobile app and a web-service, we are puzzled by the response when issuing a post request. We receive response with status 200: OK. But we can not find/extract the JSON response body.

Client client = ClientBuilder.newClient();
WebTarget webTarget = + "mobileDevices?operatorCode=KPNSCP");
String jsonString = "{\"osVersion\":\"4.1\",\"apiLevel\":16,\"devicePlatform\":\"ANDROID\"}";
Builder builder = webTarget.request();
Response response =;

We are using JAX-RS.
Can someone please provide some hints to extract the JSON body (
) from the server response?


Try this:

String output = response.getEntity(String.class);


Thanks to @Martin Spamer to mention that it will work for Jersey 1.x jars only. For Jersey 2.x use

String output = response.readEntity(String.class);