title: Jackson Serialization for subclasses
body: <p>In the below example, I have a primary class - A and its subclass - B. Both can be used as a property in the general class X.</p>
  
  <pre><code>public class A
  {
     @JsonProperty("primary_key")
     public final String primaryKey;
  
     @JsonCreator
     A(@JsonProperty("primary_key") String primaryKey)
     {
          this.primaryKey = primaryKey;
     }
  }
  public class B extends A
  {
     @JsonProperty("secondary_key")
     public final String secondaryKey;
  
     @JsonCreator
     B(@JsonProperty("primary_key") String primaryKey, @JsonProperty("secondary_key") String secondaryKey)
     {
          super(primaryKey);
          this.secondaryKey = secondaryKey;
     }
  }
  
  public class X
  {
      @JsonProperty("keys")
      public final A keys;
  
      @JsonCreator
      X(@JsonProperty("keys") A keys)
      {
           this.keys = keys;
      }
  }
  </code></pre>
  
  <p>How can I use Jackson Polymorphic feature in order to correctly deserialize the below given json into their respective classes:</p>
  
  <p>JSON A : </p>
  
  <pre><code> { "keys" :{
                "primary_key" : "abc"
            }
   }
  </code></pre>
  
  <p>JSON B : </p>
  
  <pre><code> { "keys" : {
                "primary_key" : "abc",
                "secondary_key" : "xyz"
           }
      }
  </code></pre>
  
  <p>Expected Result: Map keys object to Class A for JSON A and Class B for JSON B.</p>
  
  <p>Please suggest alternative suggestions too.</p>