title: How to process a multipart request consisting of a file and a JSON object in Spring restful service?
body: <p>I have the following resource (implemented using Spring 4.05.RELEASE) which accepts a file and a JSON object:</p>
  
  <p>(P.S. activityTemplate is a serializable entity class)</p>
  
  <pre><code>...
  @RequestMapping(value="/create", method=RequestMethod.POST)
  public @ResponseBody ActivityTemplate createActivityTemplate(
          @RequestPart ActivityTemplate activityTemplate, @RequestPart MultipartFile jarFile)
  {
     //process the file and JSON
  }
  ...
  </code></pre>
  
  <p>and this is the form I am testing from:</p>
  
  <pre><code>&lt;form method="POST" enctype="multipart/form-data"
      action="http://localhost:8080/activityTemplates/create"&gt;
      JSON: &lt;input type="text" name="activityTemplate" value='/* the JSON object*/'&gt;&lt;br /&gt;
  
      File to upload: &lt;input type="file" name="file"&gt;
      &lt;input type="submit" value="Upload"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and this is the error that I get:</p>
  
  <pre><code> There was an unexpected error (type=Unsupported Media Type, status=415).
   Content type 'application/octet-stream' not supported
  </code></pre>
  
  <p>So how should I make the resource accept the JSON object as part of the multipart request, or should I be sending the form in a different way?</p>