title: Spring controller with @RequestBody and @ModelAttribute for the same parameter
body: <p>I want to create a controller method that can be called from html form or from a standalone client using resttemplate.</p>
  
  <p>The method has this signature:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public ModelAndView save(@RequestBody @ModelAttribute(value = "itemCreateRequest")
      ItemCreateRequest request, Model model) throws NoSuchMethodException,
      SecurityException, InstantiationException, IllegalAccessException,
      IllegalArgumentException, InvocationTargetException {
  ...
  }
  </code></pre>
  
  <p>The problem is, that if I use the HTML form, everything works fine, but when I try to use the standalone client the values in the request parameter come in null.</p>
  
  <pre><code>ItemCreateRequest icr = new ItemCreateRequest();
  icr.setItem(new ItemDTO(null, "23", "bla", "bla bla"));
  restTemplate.postForLocation("http://localhost:8080/ims_ui/items.xml", icr);
  </code></pre>
  
  <p><strong>If I try the method without the @ModelAttribute the standalone client works but the HTML form not.</strong></p>
  
  <p>This is the configuration of my servlet-context.xml</p>
  
  <pre><code>    &lt;beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/&gt;
    &lt;beans:bean id="handlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"&gt;
          &lt;beans:property name="messageConverters"&gt;
              &lt;beans:list&gt;
                  &lt;beans:bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;
                      &lt;beans:property name="marshaller" ref="marshaller"/&gt;
                      &lt;beans:property name="unmarshaller" ref="marshaller"/&gt;
                  &lt;/beans:bean&gt;
                  &lt;beans:bean class="org.springframework.http.converter.StringHttpMessageConverter"/&gt;
                  &lt;beans:bean class="org.springframework.http.converter.FormHttpMessageConverter"/&gt;
              &lt;/beans:list&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
    &lt;beans:bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
      &lt;beans:property name="order" value="0" /&gt;
      &lt;beans:property name="mediaTypes"&gt;
        &lt;beans:map&gt;
          &lt;beans:entry key="jsp" value="application/html" /&gt;
          &lt;beans:entry key="xml" value="application/xml" /&gt;
        &lt;/beans:map&gt;
      &lt;/beans:property&gt;
  
      &lt;beans:property name="defaultViews"&gt;
        &lt;beans:list&gt;
          &lt;!-- XML View --&gt;
          &lt;beans:bean class="org.springframework.web.servlet.view.xml.MarshallingView"&gt;
            &lt;beans:constructor-arg ref="marshaller" /&gt;
          &lt;/beans:bean&gt;
        &lt;/beans:list&gt;
      &lt;/beans:property&gt;
    &lt;/beans:bean&gt;
  
    &lt;beans:bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
      &lt;beans:property name="contextPaths"&gt;
              &lt;beans:array&gt;
                  &lt;beans:value&gt;net.franciscovillegas.summa.ims.dto&lt;/beans:value&gt;
                  &lt;beans:value&gt;net.franciscovillegas.summa.ims.service.requests&lt;/beans:value&gt;
              &lt;/beans:array&gt;
          &lt;/beans:property&gt;
    &lt;/beans:bean&gt;
  </code></pre>
  
  <p>Thanks in advance!</p>