title: How to register my custom MessageBodyReader in my CLIENT?
body: <p>Maybe somebody can help me find out how to solve this.</p>
  
  <p>I am using jersey-apache-client 1.17</p>
  
  <p>I tried to use Jersey client to build a standalone application (no Servlet container or whatever, just the Java classes) which communicates with a RESTFUL API, and everything worked fine until I tried to handle the mediatype "text/csv; charset=utf-8" which is a CSV stream sent by the server.</p>
  
  <p>The thing is that I can read this stream with the following code:</p>
  
  <pre><code>    InputStreamReader reader = new InputStreamReader(itemExportBuilder
              .get(ClientResponse.class).getEntityInputStream());
      Csv csv = new Csv();
      Input input = csv.createInput(reader);
      try {
          String[] readLine;
          while ((readLine = input.readLine()) != null) {
              LOG.debug("Reading CSV: {}", readLine);
          }
      } catch (IOException e) {
          e.printStackTrace();
      }
      try {
          input.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>But I'd like to encapsulate it and put it into a MessageBodyReader. But after writing this code, I just can't make the client use the following class:</p>
  
  <pre><code>package client.response;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.lang.annotation.Annotation;
  import java.lang.reflect.Type;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.ws.rs.WebApplicationException;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.MultivaluedMap;
  import javax.ws.rs.ext.MessageBodyReader;
  import javax.ws.rs.ext.Provider;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  @Provider
  public class ItemExportMessageBodyReader implements MessageBodyReader&lt;ItemExportResponse&gt; {
  
  private static final Logger LOG = LoggerFactory.getLogger(ItemExportMessageBodyReader.class);
  
  private static final Integer SKU = 0;
  private static final Integer BASE_SKU = 1;
  
  public boolean isReadable(Class&lt;?&gt; paramClass, Type type, Annotation[] annotations,
          MediaType mediaType) {
      LOG.info("Cheking if content is readable or not");
      return paramClass == ItemExportResponse.class &amp;&amp; !mediaType.isWildcardType()
              &amp;&amp; !mediaType.isWildcardSubtype()
              &amp;&amp; mediaType.isCompatible(MediaType.valueOf("text/csv; charset=utf-8"));
  }
  
  public ItemExportResponse readFrom(Class&lt;ItemExportResponse&gt; paramClass, Type paramType,
          Annotation[] paramArrayOfAnnotation, MediaType paramMediaType,
          MultivaluedMap&lt;String, String&gt; paramMultivaluedMap, InputStream entityStream)
          throws IOException, WebApplicationException {
      InputStreamReader reader = new InputStreamReader(entityStream);
      Csv csv = new Csv();
      Input input = csv.createInput(reader);
      List&lt;Item&gt; items = new ArrayList&lt;Item&gt;();
      try {
          String[] readLine;
          while ((readLine = input.readLine()) != null) {
              LOG.trace("Reading CSV: {}", readLine);
              Item item = new Item();
              item.setBaseSku(readLine[BASE_SKU]);
              items.add(item);
          }
      } catch (IOException e) {
          LOG.warn("Item export HTTP response handling failed", e);
      } finally {
          try {
              input.close();
          } catch (IOException e) {
              LOG.warn("Could not close the HTTP response stream", e);
          }
      }
      ItemExportResponse response = new ItemExportResponse();
      response.setItems(items);
      return response;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The following documentation says that the preferred way of making this work in a JAX-RS client to register the message body reader with the code below:</p>
  
  <p><a href="https://jersey.java.net/documentation/latest/message-body-workers.html#d0e5658" rel="nofollow">Using Entity Providers with JAX-RS Client API</a></p>
  
  <pre><code>            Client client = ClientBuilder.newBuilder().register(MyBeanMessageBodyReader.class).build();
              Response response = client.target("http://example/comm/resource").request(MediaType.APPLICATION_XML).get();
              System.out.println(response.getStatus());
              MyBean myBean = response.readEntity(MyBean.class);
              System.out.println(myBean);
  </code></pre>
  
  <p>Now the thing is that I can't use the ClientBuilder. I have to extend from a specific class which constructs the client another way, and I have no access to change the construction.</p>
  
  <p>So when I receive the response from the server, the client fails with the following Exception:</p>
  
  <pre><code>com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class client.response.ItemExportResponse, and Java type class client.response.ItemExportResponse, and MIME media type text/csv; charset=utf-8 was not found
  </code></pre>
  
  <p>Any other way to register my MessageBodyReader?</p>