title: De-serializing JSON to polymorphic object model using Spring and JsonTypeInfo annotation
body: <p>I have the following object model in my Spring MVC (v3.2.0.RELEASE) web application:</p>
  
  <pre><code>public class Order {
    private Payment payment;
  }
  
  @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.WRAPPER_OBJECT)
  @JsonSubTypes.Type(name = "creditCardPayment", value = CreditCardPayment.class)
  public interface Payment {}
  
  
  @JsonTypeName("creditCardPayment")
  public class CreditCardPayment implements Payment {}
  </code></pre>
  
  <p>When I serialise the Order class to JSON, I get the following result (which is exactly what I want):</p>
  
  <pre><code>{
    "payment" : {
      "creditCardPayment": {
        ...
      } 
  }
  </code></pre>
  
  <p>Unfortunately, if I take the above JSON and try to de-serialise it back into my object model, I get the following exception:</p>
  
  <blockquote>
    <p>Could not read JSON: Could not resolve type id 'creditCardPayment'
    into a subtype of [simple type, class Payment] at [Source:
    org.apache.catalina.connector.CoyoteInputStream@19629355; line: 1,
    column: 58] (through reference chain: Order["payment"]); nested
    exception is com.fasterxml.jackson.databind.JsonMappingException:
    Could not resolve type id 'creditCardPayment' into a subtype of
    [simple type, class Payment] at [Source:
    org.apache.catalina.connector.CoyoteInputStream@19629355; line: 1,
    column: 58] (through reference chain: Order["payment"])</p>
  </blockquote>
  
  <p>My application is configured via Spring JavaConf, as follows:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class AppWebConf extends WebMvcConfigurerAdapter {
  
      @Bean
      public ObjectMapper objectMapper() {
          ObjectMapper objectMapper = new ObjectMapper();
          objectMapper.setSerializationInclusion(Include.NON_NULL);
          objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
          return objectMapper;
      }
  
      @Bean
      public MappingJackson2HttpMessageConverter mappingJacksonMessageConverter() {
          MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
          converter.setObjectMapper(objectMapper());
          return converter;
      }
  
      @Bean
      public Jaxb2RootElementHttpMessageConverter jaxbMessageConverter() {
          return new Jaxb2RootElementHttpMessageConverter();
      }
  
      @Override
      public void configureMessageConverters(List&lt;HttpMessageConverter&lt;?&gt;&gt; converters) {
          converters.add(jaxbMessageConverter());
          converters.add(mappingJacksonMessageConverter());
      }
  }
  </code></pre>
  
  <p>For testing, I have a controller with 2 methods, one returns an Order for HTTP GET request (this one works) and one that accepts an Order via a HTTP POST (this one fails), e.g.</p>
  
  <pre><code>@Controller
  public class TestController {
  
      @ResponseBody
      @RequestMapping(value = "/test", method = RequestMethod.GET)
      public Order getTest() {}
  
      @RequestMapping(value = "/test", method = RequestMethod.POST)
      public void postTest(@RequestBody order) {}
  
  }
  </code></pre>
  
  <p>I have tried all suggestions from the various discussions on SO but so far had no luck. Can anyone spot what I'm doing wrong?</p>