Why do bean validation Min/Max constraints not support the double type?
It is because of rounding. But not because of the problem that a double is may not correct enough to express the number you want. It is more that the annotation value (of Min
and Max
) is of type long, so it can not express any number with decimal places. On the other hand you can not use a double to express exact all numbers that a long can express.
So the API designers had to decide for one of the two ways (long or double)
Use the @DecimalMin
annotation.
You will need to pass a literal String value, because the attrubute value
must be constant (String.valueOf(- Math.PI)) doesn't work.
It works to validate Double attributes.
@DecimalMin(value = "0.01", message = "Your message...")
private Double longitude;