title: Jackson Conditional Validation of a field
body: <p>I'm trying to set up a Range Query structure on Spring with the following structure:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class QueryRange extends Query {
  
      @JsonProperty(required = true)
      @NotBlank
      @NotNull
      private String field;
  
      private Object gt;
  
      private Object gte;
  
      private Object lt;
  
      private Object lte;
  
      public String getField() {
           return field;
      }
  
      public QueryRange setField(String field) {
          this.field = field;
          return this;
      }
  
      public Object getGt() {
          return gt;
      }
  
      public QueryRange setGt(Object gt) {
          this.gt = gt;
          return this;
      }
  
      public Object getGte() {
          return gte;
      }
  
      public QueryRange setGte(Object gte) {
          this.gte = gte;
          return this;
      }
  
      public Object getLt() {
          return lt;
      }
  
      public QueryRange setLt(Object lt) {
          this.lt = lt;
          return this;
      }
  
      public Object getLte() {
          return lte;
      }
  
      public QueryRange setLte(Object lte) {
          this.lte = lte;
          return this;
      }
  
      @AssertTrue(message = "Invalid range. A value for 'gt' or 'lt' should be set.")
      private boolean isRangeSpecified() {
          return this.gt != null || this.lt != null;
      }
  
      @AssertTrue(message = "Invalid range data type. 'gt' and 'lt' must be of the same type.")
      private boolean isRangeDataTypeValid() {
          if (this.gt != null &amp;&amp; this.lt != null) {
              return this.gt.getClass().equals(this.lt.getClass());
          }
  
          return true;
      }
  }
  </code></pre>
  
  <p>The problem is that at least one of the values <strong><em>gt, gte, lt or lte</em></strong> should be not null. How can I validate that?</p>
  
  <p>I've tried Bean Validation like on the code example above, but it didn't work. Any suggestions?</p>