title: Deserialize JSON to classes
body: <p>Server returns such part of JSON:</p>
  
  <pre><code>{"condition": {
      "or": [
          {
              "and": [
                  {
                      "operand": "a",
                      "operator": "==",
                      "value": "true"
                  },
                  {
                      "not": {
                          "operand": "b",
                          "operator": "==",
                          "value": "true"
                      }
                  }
              ]
          },
          {
              "and": [
                  {
                      "operand": "b",
                      "operator": "==",
                      "value": "true"
                  },
                  {
                      "not": {
                          "operand": "a",
                          "operator": "==",
                          "value": "true"
                      }
                  }
              ]
          }
      ]
  }}
  </code></pre>
  
  <hr>
  
  <p>I wrote next classes hierarchy:</p>
  
  <pre><code>public interface Condition {}
  
  
  public class Expression implements Condition { 
     public Expression(String operator, String operand, String value) {
     } 
  }
  
  
  public class Not implements Condition { 
     public Not(Condition condition) {
     }
  }
  
  public abstract class GroupOperation implements Condition {
     public GroupOperation (List&lt;Condition&gt; conditions) {
     }
  }
  
  public class And extends GroupOperation { 
     public And(List&lt;Condition&gt; conditions) {
     }
  }
  
  public class Or extends GroupOperation { 
     public Or(List&lt;Condition&gt; conditions) {
     }
  }
  </code></pre>
  
  <p>I've added next jackson annotations in hope to deserialize JSON above:</p>
  
  <pre><code>@JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT)
  @JsonSubTypes({
      @JsonSubTypes.Type(value=Not.class, name="not"),
      @JsonSubTypes.Type(value=And.class, name="and"),
      @JsonSubTypes.Type(value=Or.class, name="or"),
      @JsonSubTypes.Type(value=Expression.class, name=""),
  })
  </code></pre>
  
  <p>I marked appropriate constructors as <code>@JsonCreator</code>.</p>
  
  <p>This doesn't work for <code>Expression</code> class.</p>
  
  <hr>
  
  <p>If I modify JSON that every <code>expression</code> object has the name "expression":</p>
  
  <pre><code>"expression" : {
      "operand": "a",
      "operator": "==",
      "value": "true"
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>@JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT)
  @JsonSubTypes({
      @JsonSubTypes.Type(value=Not.class, name="not"),
      @JsonSubTypes.Type(value=And.class, name="and"),
      @JsonSubTypes.Type(value=Or.class, name="or"),
      @JsonSubTypes.Type(value=Expression.class, name="expression"),
  })
  </code></pre>
  
  <p>It fails when trying to parse "not" condition saying that "can't instantiate abstract class need more information about type". So looks like it loses annotations declaration in deeper parsing.</p>
  
  <hr>
  
  <ol>
  <li><p>I wonder if it's possible to write deserialization with jackson for original JSON</p></li>
  <li><p>Why second approach doesn't work for <code>Not</code> deserialization</p></li>
  </ol>