title: How to validate a List<BigDecimal> with @DecimalMin and @DecimalMax?
body: <p>In my Spring project I have a POJO class with a property for a CMYK color.
  I want this property to be represented by a JSON array with exactly 4 floating-point numbers.
  Each number must be in the range between <code>0.0</code> and <code>1.0</code>.
  Currently I'm struggling with the validation of this property.</p>
  
  <p>I have researched already and found that the <code>@DecimalMin</code> and <code>@DecimalMax</code>
  annotations cannot be used on <code>Float</code> or <code>float</code> (see the answers to <a href="https://stackoverflow.com/questions/15488990/validating-double-and-float-values-using-hibernate-validator-bean-validation/15597656">this question</a>).
  Therefore I already abandoned <code>List&lt;Float&gt;</code> and use <code>List&lt;BigDecimal&gt;</code> instead.</p>
  
  <p>Here is my stripped down POJO class:</p>
  
  <pre><code>public class Settings {
  
      @NotNull
      @Size(min = 4, max = 4)
      @DecimalMin("0")
      @DecimalMax("1")
      private List&lt;BigDecimal&gt; cmykColor;
  
      public List&lt;BigDecimal&gt; getCmykColor() {
          return cmykColor;
      }
  
      public void setCmykColor(List&lt;BigDecimal&gt; cmykColor) {
          this.cmykColor = cmykColor;
      }
  }
  </code></pre>
  
  <p>and here the JUnit test:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  public class SettingsTest extends Assert {
  
      @Autowired
      private ObjectMapper objectMapper;
  
      @Autowired
      private Validator validator; // from org.springframework.validation
  
      private Errors validate(String json) throws IOException {
          Settings settings = objectMapper.readValue(json, Settings.class);
          Errors errors = new BeanPropertyBindingResult(settings, "settings");
          validator.validate(settings, errors);
          return errors;
       }
  
      @Test
      public void testValid() throws IOException {
          String json = "{ \"cmykColor\": [0.5, 1.0, 0.3, 0.0] }";
          Errors errors = validate(json);
          assertEquals(0, errors.getErrorCount());
      }
  
      @Test
      public void testTooBig() throws IOException {
          String json = "{ \"cmykColor\": [0.5, 1.01, 0.3, 0.0] }";
          Errors errors = validate(json);
          assertEquals(1, errors.getErrorCount());    
      }
  
      @Test
      public void testTooMany() throws IOException {
          String json = "{ \"cmykColor\": [0.5, 1.0, 0.3, 0.0, 0.0] }";
          Errors errors = validate(json);
          assertEquals(1, errors.getErrorCount());
          assertNotNull(errors.getFieldError("cmykColor"));
      }
  }
  </code></pre>
  
  <p>When I comment out the <code>@DecimalMin("0")</code> and <code>@DecimalMax("1")</code> annotations,
  all test-cases succeed, except of course the <code>testTooBig</code> test-case,
  which would rely on the <code>@DecimalMax</code> constraint.</p>
  
  <p>But when I add the <code>@DecimalMin("0")</code> and <code>@DecimalMax("1")</code> annotations,
  I get the following exception on <strong>all</strong> test-cases, saying that there is no validator
  for <code>DecimalMax</code> to validate <code>List&lt;BigDecimal&gt;</code>.</p>
  
  <pre><code>javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.DecimalMax' validating type 'java.util.List&lt;java.math.BigDecimal&gt;'. Check configuration for 'cmykColor'
      at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getExceptionForNullValidator(ConstraintTree.java:108)
      at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getInitializedConstraintValidator(ConstraintTree.java:140)
      at org.hibernate.validator.internal.engine.constraintvalidation.SimpleConstraintTree.validateConstraints(SimpleConstraintTree.java:55)
      at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:73)
      at org.hibernate.validator.internal.metadata.core.MetaConstraint.doValidateConstraint(MetaConstraint.java:127)
      at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:120)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:533)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForSingleDefaultGroupElement(ValidatorImpl.java:496)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:465)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:430)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:380)
      at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:169)
      at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:104)
      at com.oce.spring.domain.SettingsTest.validate(SettingsTest.java:29)
      at com.oce.spring.domain.SettingsTest.testTooMany(SettingsTest.java:58)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      ...
  </code></pre>
  
  <p>So, how am I supposed to use <code>@DecimalMin("0")</code> and <code>@DecimalMax("1")</code>
  on a <code>List&lt;BigDecimal&gt;</code> correctly?</p>