title: jackson desearlization: two keys at root. how do i unwrap one and ignore the other?
body: <p>using jackson 2.x</p>
  
  <p>the json response looks like this:</p>
  
  <pre><code>{
   "flag": true,
   "important": {
     "id": 123,
     "email": "foo@foo.com"
   }
  }
  </code></pre>
  
  <p>The "flag" key does not provide any useful information. I would like to ignore the "flag" key and unwrap the "important" value to an instance of Important.</p>
  
  <pre><code>public class Important {
  
      private Integer id;
      private String email;
  
      public Important(@JsonProperty("id") Integer id,
                       @JsonProperty("email") String email) {
          this.id = id;
          this.email = email;
      }
  
      public String getEmail() { this.email }
  
      public Integer getId() { this.id }
  }
  </code></pre>
  
  <p>When I try to add a @JsonRootName("important") to Important and configure the ObjectMapper with DeserializationFeature.UNWRAP_ROOT_VALUE I receive a JsonMappingException:</p>
  
  <blockquote>
    <p>Root name 'flag' does not match expected ('important') for type ...</p>
  </blockquote>
  
  <p>When i remove the "flag" key/value from the JSON the data binding works just fine.  I get the same result if i add @JsonIgnoreProperties("flag") to Important as well.</p>
  
  <p><strong>UPDATES</strong>
  <hr>
  updated class ... that will actually pass the compile step</p>
  
  <pre><code>@JsonRootName("important")
  public static class Important {
      private Integer id;
      private String email;
  
      @JsonCreator
      public Important(@JsonProperty("id") Integer id,
                       @JsonProperty("email") String email) {
          this.id = id;
          this.email = email;
      }
  
      public String getEmail() { return this.email; }
  
      public Integer getId() { return this.id; }
  }
  </code></pre>
  
  <p>actual test:</p>
  
  <pre><code>@Test
  public void deserializeImportant() throws IOException {
      ObjectMapper om = new ObjectMapper();
      om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
      om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
      Important important = om.readValue(getClass().getResourceAsStream("/important.json"), Important.class);
  
      assertEquals((Integer)123, important.getId());
      assertEquals("foo@foo.com", important.getEmail());
  }
  </code></pre>
  
  <p>results:</p>
  
  <blockquote>
    <blockquote>
      <p>com.fasterxml.jackson.databind.JsonMappingException: Root name 'flag' does not match expected ('important') for type [simple type, class TestImportant$Important]</p>
    </blockquote>
  </blockquote>