title: How to retrieve JSON with different value type using Jackson
body: <p>I'm using Jackson to deserialize a JSON file that is coming from an external API I cannot change, unfortunately.</p>
  
  <p>This JSON has two possible values for the <code>related</code> attribute: one as a list, when it's populated:</p>
  
  <pre><code>"related": [{
          "ID": "1694"
      }, {
          "ID": "1631"
      }, {
          "ID": "1628"
  }]
  </code></pre>
  
  <p>And <code>false</code> if it's not.</p>
  
  <pre><code>"related": [false]
  </code></pre>
  
  <p>In the second case I receive a <code>JsonMappingException</code>: </p>
  
  <pre><code>Could not read document: Can not construct instance of xxx.xxx.xxx.RelatedDTO: 
  no boolean/Boolean-argument constructor/factory method to deserialize from boolean value (false) 
  </code></pre>
  
  <p><strong>How can I manage both possible values?</strong></p>
  
  <p>This is what I have right now.</p>
  
  <pre><code>import com.fasterxml.jackson.annotation.JsonFormat;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import lombok.*;
  
  import java.time.LocalDateTime;
  import java.util.List;
  
  @Getter
  @NoArgsConstructor
  @AllArgsConstructor
  @ToString
  @EqualsAndHashCode
  @SuppressWarnings("all")
  public class MagazinePostDTO {
  
      private List&lt;MagazineRelatedDTO&gt; related;
  
      // other properties....
  
  }
  </code></pre>
  
  <p>And <code>MagazineRelatedDTO</code> is:</p>
  
  <pre><code>import com.fasterxml.jackson.annotation.JsonProperty;
  import lombok.*;
  
  @Getter
  @NoArgsConstructor
  @AllArgsConstructor
  @ToString
  @EqualsAndHashCode
  @SuppressWarnings("all")
  public class MagazineRelatedDTO {
  
      @JsonProperty("ID")
      private Integer id;
  
  } 
  </code></pre>