0

I'm getting following error while trying to do JAX-RS GET request:

MessageBodyReader not found for media type=text/plain, type=class com.intuit.accountant.services.common.cdm.Job, genericType=class com.intuit.accountant.services.common.cdm.Job

Below is my code:

Response response = target("jobs/Hello")
        .request()
        .header("intuit_offeringid", "testOfferingId")
        .header(RequestHeaders.REALM, CommonUtil.DEFAULT_REALM_ID_FOR_INTUIT_EMPLOYEE)
        .header(RequestHeaders.AUTH, "002923")
        .header(RequestHeaders.TICKET,"00303")
        .get(Response.class);

What does this error mean? How can I fix this?

eureka19
  • 1,661
  • 1
  • 18
  • 30

1 Answers1

1

You need to post all the code. The error is almost assuredly not happening in that code sample you posted. The get(Response.class) is converting it to a generic http response where you can see the response payload, status, response headers etc.

What you didn't post would most likely look somemthing like this. response.readEntity(com.intuit.accountant.services.common.cdm.Job)

In this case you don't have a reader registered to convert a text/plain response from the server to an entity. I don't know if the response was supposed to be json/xml and you are receiving text because there was an error of some kind. You should check the response as text like this to see what you are getting. This will probably point you in the right direction. If you are getting text you would have to write an implementation of MessageBodyReader to convert the plain text into an entity.

Try this...

System.out.println("Response body is " + response.getEntity(String.class));
Chris Hinshaw
  • 6,222
  • 2
  • 34
  • 59
  • 1
    The method `getEntity(Class entityType)` doesn't exist in the `Response` class, you probably meant `readEntity(Class entityType)`. – Jefferson Lima Jul 30 '17 at 16:40
  • If it is Jersey 2, then it is getEntity() https://stackoverflow.com/questions/27341788/jersey-clientresponse-getentity-of-generic-type – Chris Hinshaw Aug 03 '17 at 18:10
  • With Jersey 2 the line `response.readEntity(String.class)` will return the response body as a string, in Jersey 2 `.getEntity` doesn't accept any arguments and returns an `Object` that you can call .toString for (that for some reason gives a Connector object for me) – svarog Dec 23 '19 at 08:33