title: Jackson Deserialize To Concrete Class Based On Type
body: <p>I have what I believe should be a simple use case.</p>
  
  <p>I would like to serialize a POJO with type metadata (preferably a simple name I come up with, not the fully qualified class/package name), and later have Jackson deserialize the JSON back into the concrete class it came from by using this metadata.  There is no inheritance hierarchy among classes being serialized and deserialized.</p>
  
  <p>My scenario is I have a service which accepts multiple file types.  For each file uploaded, the client can retrieve JSON data whose structure and type depends on the file it came from.  Thus when I retrieve JSON from the service, it's not known what the concrete class is to deserialize to.  I would like Jackson to figure this out based on metadata which it supplies.</p>
  
  <p>For example, I'd like to be able to do this:</p>
  
  <pre><code>String json = ... // get JSON from the service
  Object obj = mapper.readValue(json, Object.class) // concrete class is not known
  System.out.println(obj.getClass()) // I want this to be MyConcreteClass.class
  </code></pre>
  
  <ul>
  <li>There is no inheritance hierarchy among JSON types returned.</li>
  <li>I don't want to reveal package names or other internal service
  details/structure.</li>
  <li>I have control over Jackson's serialization process</li>
  </ul>
  
  <p>Relevant question: <a href="https://stackoverflow.com/questions/28384281/can-jackson-determine-root-object-type-to-deserialize-to-when-json-includes-type">Can jackson determine root object type to deserialize to when json includes type property?</a></p>
  
  <p>Thank you so much for your help!</p>