title: Spring MockMvc UnsupportedOperationException after upgrading to new spring version
body: <p>I'm working on migration from Spring 3.2.3.RELEASE to Spring 4.2.0.RELEASE. 
  I got stuck because existing tests start failing. My code looks like (simplified):</p>
  
  <pre><code>@WebAppConfiguration
  @ContextConfiguration(classes = [TestConfig.class])
  class MvcTest extends Specification {
  
      @Autowired
      WebApplicationContext context
      MockMvc mockMvc
  
      @Subject
      MyController controller
  
      def setup() {
          controller = new MyController()
          mockMvc = MockMvcBuilders.standaloneSetup(controller).build()
      }
  
      def "should not allow to save an invalid entity"() {
      when:
  
      def result = mockMvc.perform(post("/people")
                                           .content('''{
                                              "name": "",
                                              "age": 21,
                                              "sex": 1
                                           }''')
                                           .contentType(MediaType.APPLICATION_JSON)
                                           .accept(MediaType.APPLICATION_JSON))
  
      then:
      result.andDo(print())
            .andExpect(status().isBadRequest())
            .andExpect(jsonPath('$.message').value("Name cannot be empty."))
      }
  }
  </code></pre>
  
  <p><strong>MyController.java</strong></p>
  
  <pre><code>@Controller
  public class MyController {
  
      @RequestMapping(method = RequestMethod.POST, 
              value = "/people", 
              produces = "application/json", 
              consumes = "application/json")
      @ResponseBody
      public Response create(@RequestBody @Valid Person person) {
          //save person to repository. Debugger is not even entering this line...
      }
  }
  </code></pre>
  
  <p><strong>Person.java:</strong></p>
  
  <pre><code>public class Person {
  
      private int age;
  
      @NotEmpty(message = "Name cannot be empty.")
      private String name;
  
      @NotNull
      @JsonSerialize(using = SexTypeSerializer.class)
      @JsonDeserialize(using = SexTypeDeserializer.class)
      private Sex sex;
  
      //getters, setters, other methods
  }
  </code></pre>
  
  <p><strong>TestConfig.groovy</strong></p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  class TestConfig {
  
      @Bean
      @Primary
      public ObjectMapper objectMapper() {
          def objectMapper = new ObjectMapper()
          def jacksonModule = new SimpleModule()
          jacksonModule.addDeserializer(Sex.class, new SexTypeDeserializer())
          jacksonModule.addSerializer(Sex.class, new SexTypeSerializer())
  
          objectMapper.registerModule(jacksonModule)
          objectMapper
      }
  }
  </code></pre>
  
  <p><strong>Stacktrace:</strong></p>
  
  <pre><code>java.lang.UnsupportedOperationException
  at org.springframework.test.web.servlet.setup.StubWebApplicationContext$StubBeanFactory.createBean(StubWebApplicationContext.java:369)
  at org.springframework.http.converter.json.SpringHandlerInstantiator.deserializerInstance(SpringHandlerInstantiator.java:68)
  at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.deserializerInstance(DefaultDeserializationContext.java:111)
  at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findDeserializerFromAnnotation(BasicDeserializerFactory.java:1436)
  at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.constructSettableProperty(BeanDeserializerFactory.java:765)
  at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:544)
  at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:270)
  at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:168)
  at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:401)
  at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:350)
  at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:263)
  at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:243)
  at com.fasterxml.jackson.databind.deser.DeserializerCache.hasValueDeserializerFor(DeserializerCache.java:193)
  at com.fasterxml.jackson.databind.DeserializationContext.hasValueDeserializerFor(DeserializationContext.java:344)
  at com.fasterxml.jackson.databind.ObjectMapper.canDeserialize(ObjectMapper.java:2035)
  at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.canRead(AbstractJackson2HttpMessageConverter.java:151)
  at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:187)
  at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:148)
  at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:125)
  at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78)
  at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129)
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
  </code></pre>
  
  <p>Custom serializers are also provided and were working correctly with previous version of spring. I think that there is something wrong with configuration, because of fact that such method is being called:</p>
  
  <p><strong>StubWebApplicationContext.java</strong></p>
  
  <pre><code>@Override
  public &lt;T&gt; T createBean(Class&lt;T&gt; beanClass) {
      throw new UnsupportedOperationException();
  }
  </code></pre>
  
  <p>Looks like some other implementation of createBean should be used.
  Any ideas where is the problem?</p>