Reputation: 3394
I am making a request to an API and getting a response status code of 200
.
Response of the api includes a json
response.
import javax.ws.rs.core.Response;
Response response = webclient.post(SomeReqString);
How can I retrieve the json
response as string from the web client response?
Upvotes: 40
Views: 80287
Reputation: 1
You could try
String responseAsString = response.getEntity().toString();
Upvotes: -3
Reputation: 691
You can use following code
String responseAsString = response.readEntity(String.class);
Upvotes: 69
Reputation: 19002
Try using the Response.getEntity()
method, which returns an InputStream. Then, to convert your InputStream to a String, check this question. If you really need to map the JSON String to a Java entity, that consider calling directly the Response.readEntity()
. Note that, if you consume the InputStream, you will probably have to process the input stream on your own.
Upvotes: 11