In the javadoc of @Min (javax.validation.constraints.Min) it states that only numerical values can be validated.
@Target(value={METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER}) @Retention(value=RUNTIME) @Documented @Constraint(validatedBy={}) public @interface Min
The annotated element must be a number whose value must be higher or equal to the specified minimum.
Supported types are:
BigDecimal BigInteger byte, short, int, long, and their respective wrappersNote that double and float are not supported due to rounding errors (some providers might provide some approximative support)
null elements are considered valid
When I add the annotation to a String it takes the value of the String and converts it to a BigDecimal and then checks the value. As if the String contains a BigDecimal value.
Questions:
- Where is this documented?
- Why does Eclipse Mars not accept this?
See Eclipse (compiler) message:
The javax.validation.constraints.Min constraint supports the following types: java.math.BigDecimal, java.math.BigInteger, byte, short, int, long, and their respective wrapper types.
Test.java
import javax.validation.constraints.Min;
public class Test {
@Min(10)
String quantity;
}
The code works as expected.