1

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.

Mehdi
  • 2,160
  • 6
  • 36
  • 53

1 Answers1

2

Try the following code (readEntity instead of getEntity)

String resAsString= res.readEntity(String.class);
rafaelc
  • 57,686
  • 15
  • 58
  • 82
  • I try it also. I have this error `The method readEntity(Class) is undefined for the type Response` – Mehdi Jan 08 '16 at 15:06
  • That's because either 1. You are using a version of your jaxrs library older than 2.0 or; 2. you have problems in your dependecie (have you defined the build path correctly?what about your libraries?) – rafaelc Jan 08 '16 at 15:08
  • Yes older than 2.0. why it's not possible to do this in 1.x ? – Mehdi Jan 08 '16 at 15:18
  • @Mehdi Because the method `readEntity` was added in version 2.0 – rafaelc Jan 08 '16 at 15:21