title: Polymorphic deserialization in Jackson without annotations
body: <p>I have a <code>CloudEvent&lt;T&gt;</code> class that uses polymorphic deserialization using Jackson (2.9.0 - last version) like this:</p>
  
  <pre><code>@Data
  @NoArgsConstructor
  @AllArgsConstructor
  public class CloudEvent&lt;T&gt; {
  
      @NonNull
      private String eventType;
  
      @JsonTypeInfo(
              use = JsonTypeInfo.Id.NAME,
              include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
              property = "eventType",
              defaultImpl = Void.class)
      @JsonSubTypes({
              @JsonSubTypes.Type(value = MyEvent1.class, name = "event-1"),
              @JsonSubTypes.Type(value = MyEvent2.class, name = "event-2")
      })
      private T data;
  }
  </code></pre>
  
  <p>And then deserialized with:</p>
  
  <pre><code>String cloudEventJson1 = "{\"eventType\":\"event-1\",\"data\":{\"id\":\"123\",\"details\":\"detail1\"}}";
  
  CloudEvent deserializedEvent1 = objectMapper.readValue(cloudEventJson1, CloudEvent.class);   //without subtypes
  </code></pre>
  
  <p>All this works fine.
  But because some limitations, I can not use annotations on the CloudEvent class (provided by external dependency).</p>
  
  <p>So I configured the ObjectMapper like this:</p>
  
  <pre><code>    ObjectMapper objectMapper = new ObjectMapper();
      objectMapper.registerSubtypes(new NamedType(MyEvent1.class, "event-1"));
      objectMapper.registerSubtypes(new NamedType(MyEvent2.class, "event-2"));
  
      TypeResolverBuilder  typeResolverBuilder = new ObjectMapper.DefaultTypeResolverBuilder(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE)
        .init(JsonTypeInfo.Id.NAME, null)   //CLASS works
        .inclusion(JsonTypeInfo.As.EXTERNAL_PROPERTY)
        .typeProperty("eventType")
        .typeIdVisibility(true)
  //    .defaultImpl(Void.class);
      objectMapper.setDefaultTyping(typeResolverBuilder);
  </code></pre>
  
  <p>But deserializing with same method as above does not work. It is reading the <code>eventType</code> but it is not managing to match to the registered subtype. 
  I can not use generics or TypeReferance in the deserialization because I need to use <code>spring-integration</code> for reading the events which only accepts main class; the pattern matching being done manually after deserialization.</p>
  
  <p>Exception:</p>
  
  <pre><code>com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'event-1' as a subtype of [simple type, class java.lang.Object]: known type ids = [] (for POJO property 'data')
   at [Source: (String)"{"eventType":"event-1","data":{"id":"123","details":"detail1"}}"; line: 1, column: 271]
  </code></pre>
  
  <p>Also this is configuring the ObjectMapper for all input classes. Is it possible to connect this <code>typeResolverBuilder</code> and <code>subtypes</code> to the <code>CloudEvent.class</code> (like the annotation way does it).</p>