title: Trasferring files and data with Jersey
body: <p>I'm trying to develop some rest services with Jersey to upload and download files (something like a file manager). If my services produce/consume only File class as "application/octet-stream", like in the code below, they work.</p>
  
  <pre><code>@GET
  @Produces("application/octet-stream")
  public File getFile(String id) {
      try {
          File file = new File(System.getProperty("user.home"), id);
          return file;
      } catch (FileNotFoundException ex) {
          Logger.getLogger(GenericResource.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IOException ex) {
          Logger.getLogger(GenericResource.class.getName()).log(Level.SEVERE, null, ex);
      }
      return null;
  }
  </code></pre>
  
  <p>But if I try to transfer a custom object that contains a File field and some other data (FileEnvelope in the sample) I obtain an error.</p>
  
  <pre><code>@GET
  @Produces("application/octet-stream")
  public FileEnvelope getXml(String id) {
      try {
          File file = new File(System.getProperty("user.home"), id);
          FileEnvelope fileEnvelope = new FileEnvelope(file, "text");
          return fileEnvelope;
      } catch (FileNotFoundException ex) {
          Logger.getLogger(GenericResource.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IOException ex) {
          Logger.getLogger(GenericResource.class.getName()).log(Level.SEVERE, null, ex);
      }
      return null;
  }
  </code></pre>
  
  <p>The error is </p>
  
  <blockquote>
    <p>Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class com.mycompany.restdemo.FileEnvelope, and Java type class com.mycompany.restdemo.FileEnvelope, and MIME media type application/octet-stream was not found</p>
  </blockquote>
  
  <p>Where I'm wrong? Is this the right way to manage this case? My client could not be a "Jersey client".</p>