title: Java: Jackson polymorphic JSON deserialization of an object with an interface property?
body: <p>I am using Jackson's <code>ObjectMapper</code> to deserialize a JSON representation of an object that contains an interface as one of its properties. A simplified version of the code can be seen here:</p>
  
  <p><a href="https://gist.github.com/sscovil/8735923">https://gist.github.com/sscovil/8735923</a></p>
  
  <p>Basically, I have a class <code>Asset</code> with two properties: <code>type</code> and <code>properties</code>. The JSON model looks like this:</p>
  
  <pre><code>{
      "type": "document",
      "properties": {
          "source": "foo",
          "proxy": "bar"
      }
  }
  </code></pre>
  
  <p>The <code>properties</code> property is defined as an interface called <code>AssetProperties</code>, and I have several classes that implement it (e.g. <code>DocumentAssetProperties</code>, <code>ImageAssetProperties</code>). The idea is that image files have different properties (height, width) than document files, etc.</p>
  
  <p>I've worked off of the examples in <a href="http://programmerbruce.blogspot.com/2011/05/deserialize-json-with-jackson-into.html">this article</a>, read through docs and questions here on SO and beyond, and experimented with different configurations in the <code>@JsonTypeInfo</code> annotation parameters, but haven't been able to crack this nut. Any help would be greatly appreciated.</p>
  
  <p>Most recently, the exception I'm getting is this:</p>
  
  <pre><code>java.lang.AssertionError: Could not deserialize JSON.
  ...
  Caused by: org.codehaus.jackson.map.JsonMappingException: Could not resolve type id 'source' into a subtype of [simple type, class AssetProperties]
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <p><strong>SOLUTION:</strong></p>
  
  <p>With many thanks to @Michał Ziober, I was able to resolve this issue. I was also able to use an Enum as a type id, which took a bit of Googling. Here is an updated Gist with working code:</p>
  
  <p><a href="https://gist.github.com/sscovil/8788339">https://gist.github.com/sscovil/8788339</a></p>