java - How to use @Size validation while using Float field with javax library? -
i trying utilize maximum size validation float
datatype javax validations. here example
@notnull @size(min = 5, max = 10) public float getphone(){ }
but getting error can't utilize size validation float datatype. ideas?
@size
not work float types. quote javadocs of constraint:
/** * annotated element size must between specified boundaries (included). * <p/> * supported types are: * <ul> * <li>{@code charsequence} (length of character sequence evaluated)</li> * <li>{@code collection} (collection size evaluated)</li> * <li>{@code map} (map size evaluated)</li> * <li>array (array length evaluated)</li> * </ul> * <p/> * {@code null} elements considered valid. * */
so constraints size of string or collection. write own validator float , register via xml - see http://beanvalidation.org/1.1/spec/#xml-mapping-constraintdefinition
however, recommend against it, since not create sense speak "size" in context want utilize it.
you utilize @min
, @max
, not providers back upwards float info type, due problem of rounding.
looking @ example, seems want store phone number. why ever take float begin with?
java validation hibernate-validator
No comments:
Post a Comment