title: Jackson deserialization of type with different objects
body: <p>I have a result from a web service that returns either a boolean value or a singleton map, e.g.</p>
  
  <p>Boolean result:</p>
  
  <pre><code>{
      id: 24428,
      rated: false
  }
  </code></pre>
  
  <p>Map result:</p>
  
  <pre><code>{
      id: 78,
      rated: {
          value: 10
      }
  }
  </code></pre>
  
  <p>Individually I can map both of these easily, but how do I do it generically?</p>
  
  <p>Basically I want to map it to a class like:</p>
  
  <pre><code>public class Rating {
      private int id;
      private int rated;
      ...
      public void setRated(?) {
          // if value == false, set rated = -1;
          // else decode "value" as rated
      }
  }
  </code></pre>
  
  <p>All of the polymorphic examples use <code>@JsonTypeInfo</code> to map based on a property in the data, but I don't have that option in this case.</p>
  
  <p><hr>
  <strong>EDIT</strong><br>
  The updated section of code:</p>
  
  <pre><code>@JsonProperty("rated")
  public void setRating(JsonNode ratedNode) {
      JsonNode valueNode = ratedNode.get("value");
      // if the node doesn't exist then it's the boolean value
      if (valueNode == null) {
          // Use a default value
          this.rating = -1;
      } else {
          // Convert the value to an integer
          this.rating = valueNode.asInt();
      }
  }
  </code></pre>