Search code examples
javarestjavax.ws.rs

Extract String from javax Response


Please, I have this Response and I want to extract the content as a String

Response res = Response.status(Response.Status.OK)
                .entity(new GenericEntity<MongoType>(app) {
                }).type(MediaType.APPLICATION_XML_TYPE).build();

How can I do that ?

I'm using javax.ws.rs.core library

I'm trying res.getEntity(String.class); but it does not take a String.class on their parameter.


Solution

  • Try the following code (readEntity instead of getEntity)

    String resAsString= res.readEntity(String.class);