title: Tunneling MultipartFile
body: <p>I have a <code>spring</code> controller that accepts a class named <code>FileUploadBean</code> on <code>POST</code>. The controller method looks like that:</p>
  
  <p><strong>First Controller</strong>:</p>
  
  <pre><code>@RequestMapping(value = "/upload", method = RequestMethod.POST)
  @ResponseBody
  public ResponseEntity&lt;byte[]&gt; uploadFile(final FileUploadBean fileUploadBean) throws IOException {
     // Some code that works fine here
  } 
  </code></pre>
  
  <p>One of the <code>FileUploadBean</code> properties is of type <code>MultipartFile</code>.</p>
  
  <p>Now, I'm trying to add some sort of wrapper controller (that will run on another server) that also accepts <code>FileUploadBean</code> and just forwards the request to the first controller:</p>
  
  <p><strong>Second (wrapper) Controller</strong>:</p>
  
  <pre><code>@RequestMapping(value="/upload", method = RequestMethod.POST)
  @ResponseBody
  public ResponseEntity&lt;byte[]&gt; uploadImage(final FileUploadBean fileUploadBean) throws IOException {
    ResponseEntity&lt;byte[]&gt; response = restTemplate.postForEntity([first controller url here], fileUploadBean, byte[].class);
    return response;
  }
  </code></pre>
  
  <p>When I'm sending the request to the first controller I get: </p>
  
  <blockquote>
  <pre><code>org.springframework.http.converter.HttpMessageNotWritableException:
  </code></pre>
    
    <p>Could not write JSON: No serializer found for class
    java.io.FileDescriptor and no properties discovered to create
    BeanSerializer (to avoid exception, disable
    SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain:
    com.outbrain.images.beans.FileUploadBean["file"]-&gt;org.springframework.web.multipart.commons.CommonsMultipartFile["fileItem"]-&gt;org.apache.commons.fileupload.disk.DiskFileItem["inputStream"]-&gt;java.io.FileInputStream["fd"]);
    nested exception is
    com.fasterxml.jackson.databind.JsonMappingException: No serializer
    found for class java.io.FileDescriptor and no properties discovered to
    create BeanSerializer (to avoid exception, disable
    SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain:
    com.outbrain.images.beans.FileUploadBean["file"]-&gt;org.springframework.web.multipart.commons.CommonsMultipartFile["fileItem"]-&gt;org.apache.commons.fileupload.disk.DiskFileItem["inputStream"]-&gt;java.io.FileInputStream["fd"])
          at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.writeInternal</p>
  </blockquote>
  
  <p>How can I make this request work?</p>