title: Multiple level @JsonTypeInfo and @JsonSubTypes
body: <p>I have class hierarchy A &lt;- B &lt;- C. I don't want class A to be aware of C, so I intend to use A.type=&quot;B&quot; to indicate it to be class B, and then B.type2=&quot;C&quot; to indicate it to be class C.</p>
  <pre class="lang-java prettyprint-override"><code>@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = &quot;type&quot;)
  @JsonSubTypes({@JsonSubTypes.Type(value = B.class, name = &quot;B&quot;)})
  public abstract class A {
  
      private final String type;
  
      public A(String type) {
          this.type = type;
      }
  }
  
  @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = &quot;type2&quot;)
  @JsonSubTypes({@JsonSubTypes.Type(value = C.class, name = &quot;C&quot;)})
  public class B extends A {
  
      private final String type2;
  
      private final String propertyB;
  
      @JsonCreator
      public B(@JsonProperty(&quot;type2&quot;) String type2,
               @JsonProperty(&quot;propertyB&quot;) String propertyB) {
          super(&quot;B&quot;);
          this.type2 = type2;
          this.propertyB = propertyB;
      }
  }
  
  public class C extends B {
  
      private final String propertyC;
  
      @JsonCreator
      public C(@JsonProperty(&quot;propertyB&quot;) String propertyB,
               @JsonProperty(&quot;propertyC&quot;) String propertyC) {
          super(&quot;C&quot;, propertyB);
          this.propertyC = propertyC;
      }
  }
  </code></pre>
  <p>When I read JSON of C to class A, the actual Java object is class B but not C.</p>
  <pre><code>@Test
  void whenReadCJsonToA_thenObjectIsInstanceOfC() throws JsonProcessingException {
  
      String json = &quot;{\n&quot; +
                    &quot;  \&quot;type\&quot; : \&quot;B\&quot;,\n&quot; +
                    &quot;  \&quot;type2\&quot; : \&quot;C\&quot;,\n&quot; +
                    &quot;  \&quot;propertyB\&quot; : \&quot;b\&quot;,\n&quot; +
                    &quot;  \&quot;propertyC\&quot; : \&quot;c\&quot;\n&quot; +
                    &quot;}&quot;;
  
      A obj = objectMapper.readValue(json, A.class);
      assertTrue(obj instanceof B, &quot;obj is not instance of B&quot;);  // pass
      assertTrue(obj instanceof C, &quot;obj is not instance of C&quot;);  // fail
  }
  </code></pre>
  <p>One way to make above test pass is <a href="https://github.com/yejianfengblue/cascade-JsonTypeInfo/tree/custom-deserializer" rel="nofollow noreferrer">writing custom deserializer</a>, but this solution is tedious if the class holds many fields.</p>
  <p>Is it possible to make above test pass with a more elegant way? Is my indention to cascade @JsonTypeInfo and @JsonSubTypes completely wrong?</p>
  <p>My maven project can be found in <a href="https://github.com/yejianfengblue/cascade-JsonTypeInfo" rel="nofollow noreferrer">Github</a>.</p>