Serialize and deserialize an object with an abstract field using jackson
<p>What I'd like to do seems simple, just handling an object like the following:</p>

<ol>
<li>When receiving a Post request from a client(web browser), which has a JSON object in its body, the server deserializes it into a certain object, and serializes some of its fields then saves them into a database. </li>
<li>When receiving a Get request from the client, the server retrieves the object from the database, deserializes it, composes it with other information and gives it back to the client.</li>
</ol>

<p>The problem is, the object contains an abstract field.</p>

<h3>Saving a request works fine</h3>

<p>When I add these annotations to the abstract class, the phase 1 works fine.</p>

<p>Request JSON:</p>

<pre><code>{ config: { type: "concreteA", ...}, ...}
</code></pre>

<p>REST API:</p>

<pre><code>@RequestMapping(value="/configs", method=RequestMethod.POST)
@ResponseBody
public ResponseEntity&lt;Object&gt; saveConfig(@RequestBody ConfigRequest request) 
throws IOException {
...
}
</code></pre>

<p>ConfigRequest class:</p>

<pre><code>public class ConfigRequest {
    private AbstractConfig config;
    // Abbr. other fields, and all getters and setters 
}
</code></pre>

<p>AbstractConfig class, which is included in ConfigRequest</p>

<pre><code>@JsonTypeInfo(use=JsonTypeInfo.Id.NAME,
              include=JsonTypeInfo.As.PROPERTY,
              property="type",
              visible=true)
@JsonSubTypes({@Type(value=ConcreteAConfig.class, name="concreteA")})
public abstract class AbstractConfig {
    public AbstractConfig(){}
    private String type;
    // Abbr. other fields, and all getters and setters 
}
</code></pre>

<p>Deserialized string:</p>

<pre><code>{"type":"concreteA", ...}
</code></pre>

<h3>Deserializing the json string fails</h3>

<p>But when I try retrieving and deserializing(Phase 2), the deserialization fails: </p>

<pre><code>16/03/24 17:17:20 ERROR (...Abbr...) org.codehaus.jackson.map.JsonMappingException: Can not construct instance of AbstractConfig, problem: abstract types can only be instantiated with additional type information
</code></pre>

<p>RowMapper, which raises the error:</p>

<pre><code>public class BatchRowMapper implements RowMapper&lt;Batch&gt; {
  private static ObjectMapper objectMapper = new ObjectMapper();

  @Override
  public Batch mapRow(ResultSet row, int rowNum) throws SQLException {
    Batch batch = new Batch();

    try {
      // THIS METHOD RAISES THE ERROR
      batch.setConfig(objectMapper.readValue(row.getString(CONFIG), AbstractConfig.class));
    } catch (ClassCastException|IOException e) {
      throw new SQLException(e.toString());
    }

    return batch;
  }
}
</code></pre>

<p>I'd like to ser/de an abstract field with the same "type" field, and using only annotaions is my wish... Is it possible? If further information needed, I will be willing.
Thank you in advance.</p>