reading JSON response as string using jersey client
I was able to find solution to the problem. Just had to call bufferEntity method before getEntity(String.class). This will return response as string.
clientResp.bufferEntity();
String x = clientResp.getEntity(String.class);
Although the above answer is correct, using Jersey API v2.7 it is slightly different with Response
:
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080");
Response response = target.path("api").path("server").path("ping").request(MediaType.TEXT_PLAIN_TYPE).get();
System.out.println("Response: " + response.getStatus() + " - " + response.readEntity(String.class));