title: Dynamic polymorphic type handling with Jackson
body: <p>I have a class hierarchy similar to this one:</p>
  
  <pre><code>public static class BaseConfiguration {
  }
  
  public abstract class Base {
    private BaseConfiguration configuration;
    public String id;
  
    public BaseConfiguration getConfiguration() { ... }
    public void setConfiguration(BaseConfiguration configuration) { ... }
  }
  
  public class A extends Base {
     public static class CustomConfigurationA extends BaseConfiguration {
         String filename;
         String encoding;
     }
  
     CustomConfigurationA getConfiguration() { ... }
  }
  
  class B extends Base {
     public static class CustomConfigurationB extends BaseConfiguration {
         /* ... */
     }
  
     CustomConfigurationB getConfiguration() { ... }
  }
  </code></pre>
  
  <p>And json input like this one (which I cannot change myself)</p>
  
  <pre><code>{
      "id":"File1",
      "configuration":{
           "filename":"...",
           "encoding":"UTF-8"
       }
  }
  </code></pre>
  
  <p>I am parsing the JSON in Java with Jackson like this</p>
  
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  value = mapper.readValue(in, nodeType);
  </code></pre>
  
  <p>I want to deserialize classes A, B and others from JSON using JAVA/Jackson. There are no type information embedded in JSON (and can't be). I can't use annotations on the classes (I don't own them) and I (believe) I can't use mixins since there are potentially arbitrary numbers of classes like A &amp; B (and mixins are not dynamic). Good thing is that the deserializing code knows which is the correct custom class to use for deserializing (basically there is a known mapping from class to configuration class), but I do not know how make Jackson recognize this information when deserializing the JSON.</p>
  
  <p>In short: I want to be able to resolve the deserialization type of the configuration object  depending on the surrounding class type by setting whatever is necessary on ObjectMapper. How can this be achieved?</p>