How to retrieve JSON Response from a javax.ws.rs.core.Response response?

后端 未结 2 541
盖世英雄少女心
盖世英雄少女心 2020-12-20 10:53

I am making a request to an API and getting a response status code of 200.

Response of the api includes a json response.

i         


        
相关标签:
2条回答
  • 2020-12-20 11:21

    You can use following code

    String responseAsString = response.readEntity(String.class);
    
    0 讨论(0)
  • 2020-12-20 11:23

    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.

    0 讨论(0)
提交回复
热议问题