title: Mapping multipart form-data to object
body: <p>I have to write a REST API whcih consumes <code>multipart/form-data</code>. When I write the method like below , it works fine</p>
  <pre><code>@RequestMapping(value=&quot;/addSftp&quot;, method=RequestMethod.POST)
  public HashMap&lt;String, Object&gt; welcome( HttpServletRequest request,@RequestParam(value=&quot;selectedFile&quot;, required=false) MultipartFile selectedFile,
          @RequestParam(value=&quot;sftp_name&quot;) String sftp_name,
          @RequestParam(value=&quot;ip_address&quot;)String ip_address,
          @RequestParam(value=&quot;port_number&quot;)String port_number,
          @RequestParam(value=&quot;userName&quot;)String userName,
          @RequestParam(value=&quot;password&quot;)String password,
          @RequestParam(value=&quot;customRadioInline1&quot;)String customRadioInline1) {
      HashMap map = new HashMap&lt;String, Object&gt;();
      System.out.println(sftp_name);
      System.out.println(ip_address);
      System.out.println(port_number);
      System.out.println(userName);
      System.out.println(password);
      System.out.println(customRadioInline1);
      System.out.println(selectedFile);
      map.put(&quot;stat&quot;, &quot;success&quot;);
       return map;
                }
  </code></pre>
  <p>I want to map the request to a bean. Below is my bean</p>
  <pre><code>public class SftpBean {
  
      private String sftp_name;
      private String ip_address; 
      private String port_number;
      private String userName;
      private String password;
      private String customRadioInline1;
      private MultipartFile selectedFile;
  
  //getters and setters here
  
  }
  </code></pre>
  <p>But when I write the method like below , I am getting exception</p>
  <pre><code>public HashMap&lt;String, Object&gt; welcome( @RequestBody SftpBean sftpBean) {
      HashMap map = new HashMap&lt;String, Object&gt;();
      System.out.println(sftpBean.getIpAddress());
      //similar statements for priniting other parameters
      map.put(&quot;stat&quot;, &quot;success&quot;);
       return map;
  }
  </code></pre>
  <p>Here is my exception</p>
  <pre><code>Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: 
      Content type 'multipart/form-data;boundary=---------------------------246741595337214313524058968681;charset=UTF-8' not supported]
  </code></pre>
  <p>Here is my request payload</p>
  <pre><code>-----------------------------317042354532732980343175029806
  Content-Disposition: form-data; name=&quot;sftp_name&quot;
  
  ABC
  -----------------------------317042354532732980343175029806
  Content-Disposition: form-data; name=&quot;ip_address&quot;
  
  123
  -----------------------------317042354532732980343175029806
  Content-Disposition: form-data; name=&quot;port_number&quot;
  
  456
  -----------------------------317042354532732980343175029806
  Content-Disposition: form-data; name=&quot;userName&quot;
  
  demo
  -----------------------------317042354532732980343175029806
  Content-Disposition: form-data; name=&quot;password&quot;
  
  demo123
  -----------------------------317042354532732980343175029806
  Content-Disposition: form-data; name=&quot;customRadioInline1&quot;
  
  pwd
  -----------------------------317042354532732980343175029806
  Content-Disposition: form-data; name=&quot;selectedFile&quot;; filename=&quot;details.txt&quot;
  Content-Type: text/plain
  </code></pre>
  <p>Is there a way to directly map the request to my <code>SftpBean</code>?</p>