title: @RequestPart is always null with Multipart Request, Spring MVC 3.2.4
body: <p>I am developing a small RESTful service based on Spring 3.2.4 and following <a href="https://github.com/rstoyanchev/spring-mvc-31-update/blob/master/multipart-requests/slides.md" rel="nofollow">this article</a> to write a custom function to send Multipart Requests. </p>
  
  <p>Firstly, in the controller, I wrote the sample function to test</p>
  
  <pre><code>@RequestMapping(value = "/createUser", method = RequestMethod.POST)
  public @ResponseBody String createUser(@RequestBody User user)
  {
      if (user != null) {
          log.debug("Username: " + user.getUsername());
      }
  
      return "Successfully created!";
  }
  </code></pre>
  
  <p>The User object contains a user information which is using <strong>Jackson JSON</strong> to get and parse data. I also used the cURL to send request and the command I tested</p>
  
  <pre><code>curl http://localhost:8080/user/createUser --data-binary @test.txt -X POST -i -H "Content-Type: application/json"
  </code></pre>
  
  <p>This is the <strong>text.txt</strong></p>
  
  <pre><code>{    
      "id" : "123456",
      "username" : "YOUR_USERNAME",
      "password" : "YOUR_PASSWORD",
      "email" : "YOUR_EMAIL"
  }
  </code></pre>
  
  <p>The application returned "Successfully created!" and logged the username. It worked fine.</p>
  
  <p>Secondly, I thought everything would be simple but I was wrong. When I wrote the following function to send Multipart Requests with the User and MultipartFile objects. </p>
  
  <pre><code>@RequestMapping(
          value = "/createUser", 
          method = RequestMethod.POST, 
          consumes = {"multipart/mixed", "multipart/form-data"})
  public @ResponseBody String createUser(
             @RequestPart("user") @Valid User user, 
             @RequestPart("file") MultipartFile file) {
  
      if (user != null) {
          log.debug("Username: " + user.getUsername());    // The username is null
      }
  
      return "Successfully created!";
  }
  </code></pre>
  
  <p>I continued to use the cURL to test with the command</p>
  
  <pre><code>curl http://localhost:8080/user/createUser --data-binary @test.txt -X POST -i -H "Content-Type: multipart/mixed; boundary=4ebf00fbcf09"
  </code></pre>
  
  <p>And the <strong>text.txt</strong> file was changed</p>
  
  <pre><code>--4ebf00fbcf09
  Content-Disposition: form-data; name="user"
  Content-Type: application/json; charset=UTF-8
  Content-Transfer-Encoding: 8bit
  
  {    
      "id" : "123456",
      "username" : "YOUR_USERNAME",
      "password" : "YOUR_PASSWORD",
      "email" : "YOUR_EMAIL"
  }
  
  --4ebf00fbcf09
  Content-Disposition: form-data; name="file"; filename="no_thumb.jpg"
  Content-Type: image/jpeg
  Content-Transfer-Encoding: base64
  
  &lt;... File Data ...&gt;
  
  --4ebf00fbcf09--
  </code></pre>
  
  <p>I am facing the problem that the @RequestPart is always <strong>NULL</strong>. Details:</p>
  
  <ul>
  <li>The application returned "Successfully created!"</li>
  <li>The User object was not null but the server logged the <strong>"Username: null"</strong> and MultipartFile object was too.</li>
  </ul>
  
  <p>How can I fix it? </p>
  
  <p>Please help me to solve this issue.</p>