Hi,
consider the following constraint definition
Code:
@Min(1L)
Long number;
then the validation attempt
Validator#validateValue(<type>, "number", "0") leads to
Code:
javax.validation.UnexpectedTypeException: There are multiple validators which could validate the type class java.lang.Long. The validator classes are: class java.lang.Number, class java.lang.String
at org.hibernate.validation.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:242)
The reason is in
ConstraintTree#findMatchingValidatorClass(Object, Type). I'm really not sure, but maybe this implementation would be more suitable. If the value is not null, and a validator exists that is suitable for the values type, just use it.
But I've to admit, I don't know which side effects this may have...
Code:
if (value != null && validatorsTypes.containsKey(value.getClass()))
return validatorsTypes.get(value.getClass());
resolveAssignableTypes(suitableTypes);
verifyResolveWasUnique( type, suitableTypes );
return validatorsTypes.get( suitableTypes.get( 0 ) );
Anyway, I'm unsure if this is a bug, an error in the constraint definition or something that was never supposed to work... But validating that a String is a valid Number seems to be a common task.
Thanks,
Ron
hibernate-validator-4.0.0.beta3