title: Jersey client can't specify media type
body: <p>I have a get call to a rest service (that works fine), and I would like to change it and use jersey.
  I downloaded the last JARs from the official site and put them inside my project.
  All my response thrown exceptions (except this: <code>String response = invocationBuilder.get(String.class);</code>):</p>
  
  <pre><code>javax.ws.rs.NotAcceptableException: HTTP 406 Not Acceptable
      at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1014)
      at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:816)
      at org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92)
      at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:700)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
      at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:696)
      at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:420)
      at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:316)
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>        ClientConfig clientConfig = new ClientConfig();
  
          Client client = ClientBuilder.newClient(clientConfig);
          //not so orthodox... 
          WebTarget webTarget = client.target(uri);//uri= https://www.foo.bar/api/v1.0/sms/sendMessage?accessKeyId=34TR&amp;idCampaign=4&amp;fromNumber=Test&amp;toNumber=393281234567&amp;message=Inserisci+la+seguente+password%3A+8c495b
  
          Invocation.Builder invocationBuilder2 =
                  webTarget.request(MediaType.APPLICATION_JSON);
          Invocation.Builder invocationBuilder =
                  webTarget.request();//------NO MEDIA TYPE SPECIFICATION
          Invocation.Builder invocationBuilder3 =
                  webTarget.request(MediaType.APPLICATION_XML_TYPE);
          Invocation.Builder invocationBuilder4 =
                  webTarget.request(MediaType.TEXT_XML_TYPE);
          Invocation.Builder invocationBuilder5 =
                  webTarget.request(MediaType.TEXT_PLAIN_TYPE);
          Invocation.Builder invocationBuilder6 =
                  webTarget.request(MediaType.APPLICATION_FORM_URLENCODED);
  
          try {
              String response2 = invocationBuilder2.get(String.class);
          } catch (Exception e) {System.out.println(e);}
          try {
      //WORKS ONLY THIS, WITH NO MEDIA TYPE SPECIFICATION
              String response = invocationBuilder.get(String.class); 
          } catch (Exception e) {System.out.println(e);}
          try {
              String response3 = invocationBuilder3.get(String.class);
          } catch (Exception e) {System.out.println(e);}
          try {
              String response4 = invocationBuilder4.get(String.class);
          } catch (Exception e) {System.out.println(e);}
          try {
              String response5 = invocationBuilder5.get(String.class);
          } catch (Exception e) {System.out.println(e);}
          try {
              String response6 = invocationBuilder6.get(String.class);
          } catch (Exception e) {System.out.println(e);}
  
  //NONE OF THIS WORKS (last part of the test):
          try {
          SmsResponse response02 = invocationBuilder2.get(SmsResponse.class);
          } catch (Exception e) {System.out.println(e);}
          try {
          SmsResponse response0 = invocationBuilder.get(SmsResponse.class);
          } catch (Exception e) {System.out.println(e);}
          try {
          SmsResponse response03 = invocationBuilder3.get(SmsResponse.class);
          } catch (Exception e) {System.out.println(e);}
          try {
          SmsResponse response04 = invocationBuilder4.get(SmsResponse.class);
          } catch (Exception e) {System.out.println(e);}
          try {
          SmsResponse response05 = invocationBuilder5.get(SmsResponse.class);
          } catch (Exception e) {System.out.println(e);}
          try {
          SmsResponse response06 = invocationBuilder6.get(SmsResponse.class);
          } catch (Exception e) {System.out.println(e);}
  </code></pre>
  
  <p>The <em>response</em> string is a JSON:  <code>{"status":"success","uid":"407077","numSms":1,"errorMsg":false}</code></p>
  
  <p>But I get an exception while trying to obtain a <em>SmsResponse</em> object (last part of code), <em>response0</em> thrown the exception below (the other cases thrown the previous 406 exception):</p>
  
  <pre><code> org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/json;charset=UTF-8, type=class it.sian.zfab.SmsResponse, genericType=class it.sian.zfab.SmsResponse.
      at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:808)
      at org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92)
      at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:700)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
      at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:696)
      at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:420)
      at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:316)
  </code></pre>
  
  <p>The bean:</p>
  
  <pre><code>@XmlRootElement
  public class SmsResponse implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @QueryParam("uid")
      private String uid;
  
      @QueryParam("status")
      private String status;
  
      @QueryParam("errorMsg")
      private String errorMsg;
  
      @QueryParam("numSms")
      private Integer numSms;
  
      //getter and setter...
  }
  </code></pre>
  
  <p>My old method (that works), here you can see that it's working fine with content application/json:</p>
  
  <pre><code>private &lt;T&gt; T restCallJson(String uri, Class&lt;T&gt; returnType)
  {
      T objectResponse = null;
      try {
          URL url = new URL(uri);
          HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
          connection.setRequestMethod("GET");
          connection.setRequestProperty("Content-Type", "application/json");
  
          InputStream inputStream = connection.getInputStream();
  
          Gson gson = new Gson();
          final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
          objectResponse = gson.fromJson(reader, returnType);
  
          connection.disconnect();            
      }
      catch (Exception e)
      {
          log.error("WebServiceUtility - restCallJson: " + e);
      }
      return objectResponse;
  }
  </code></pre>
  
  <p>1) Why cannot I specify the MediaType? Which one should I use?</p>
  
  <p>2) Why cannot I retrieve directly the SmsResponse object?</p>