title: Spring 3.1+ argument resolver cannot handle proprietary Person class argument
body: <p>I just upgraded from Spring 3.0 to 3.2. I've configured a custom argument resolver like this in my spring configuration xml file:</p>
  
  <pre><code>&lt;mvc:annotation-driven&gt;
    &lt;mvc:argument-resolvers&gt;
      &lt;bean class="mycompany.api.PersonResolver" /&gt;   
    &lt;/mvc:argument-resolvers&gt;
  &lt;/mvc:annotation-driven&gt;
  </code></pre>
  
  <p>My Spring MVC controller has a method like this:</p>
  
  <pre><code>@RequestMapping(value="/api/doSomething", method=RequestMethod.POST)
  public @ResponseBody JsonNode handleRestCall(Person person) {
    ...
    return jsonNode;
  }
  </code></pre>
  
  <p>Where the Person class is our own proprietary class.</p>
  
  <p>However, this does NOT work. It gives me an error:</p>
  
  <pre><code>Rest call error argument type mismatch
  HandlerMethod details: 
      Controller [MyController]
      ...
      Resolved arguments: 
      [0] [type=org.springframework.validation.support.BindingAwareModelMap] [value=    {org.springframework.validation.BindingResult.objectNode=org.springframework.validation.BeanPropertyBindingResult: 0 errors}]
  
      java.lang.IllegalArgumentException: argument type mismatch
  </code></pre>
  
  <p>It appears that changing my Person argument type to some other type (in my case: PersonWrapper, containing a reference to a Person) offers me a workaround for the problem, i.e. Spring can now resolve the argument. </p>
  
  <p>Can someone explain this to me? Is this because Spring uses java Reflection and has some name clash with some Spring Person class (Spring security has a org.springframework.security.ldap.userdetails.Person class) ? </p>
  
  <p>Implementation of my resolver:
  My initial implementation looked like:</p>
  
  <pre><code>import mycompany.Person;
  
  public class PersonResolver implements HandlerMethodArgumentResolver  {
      public boolean supportsParameter(MethodParameter mp) {
        return mp.getParameterType().equals(Person.class);
  }
  
      public Object resolveArgument(MethodParameter mp, ModelAndViewContainer mavc, NativeWebRequest nwr, WebDataBinderFactory wdbf) throws Exception {
        if(mp.getParameterType().equals(Person.class)) {
          ...
          return somePerson;
        }
        return UNRESOLVED;
      }
  }
  </code></pre>
  
  <p>Spring configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p" 
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.2.xsd
          http://www.springframework.org/schema/mvc   http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"&gt;
  
      &lt;context:annotation-config /&gt; 
  
      &lt;!-- automatically search for Controller classes using @Controller annotation --&gt;
      &lt;context:component-scan base-package="mycompany.api"/&gt;
  
      &lt;!-- we use Spring 3 annotation driven development --&gt;
      &lt;mvc:annotation-driven&gt;
          &lt;mvc:argument-resolvers&gt;
                  &lt;bean class="mycompany.api.PersonResolver" /&gt;   
                  &lt;bean class="mycompany.api.SessionLocaleResolver"/&gt;
          &lt;/mvc:argument-resolvers&gt;
      &lt;/mvc:annotation-driven&gt;
  
  &lt;/beans&gt;
  </code></pre>