use of jakarta.validation.constraints.PositiveOrZero in project jsonschema-generator by victools.
the class JakartaValidationModule method resolveNumberInclusiveMinimum.
/**
* Determine a number type's minimum (inclusive) value.
*
* @param member the field or method to check
* @return specified inclusive minimum value (or null)
* @see Min
* @see DecimalMin
* @see PositiveOrZero
*/
protected BigDecimal resolveNumberInclusiveMinimum(MemberScope<?, ?> member) {
Min minAnnotation = this.getAnnotationFromFieldOrGetter(member, Min.class, Min::groups);
if (minAnnotation != null) {
return new BigDecimal(minAnnotation.value());
}
DecimalMin decimalMinAnnotation = this.getAnnotationFromFieldOrGetter(member, DecimalMin.class, DecimalMin::groups);
if (decimalMinAnnotation != null && decimalMinAnnotation.inclusive()) {
return new BigDecimal(decimalMinAnnotation.value());
}
PositiveOrZero positiveAnnotation = this.getAnnotationFromFieldOrGetter(member, PositiveOrZero.class, PositiveOrZero::groups);
if (positiveAnnotation != null) {
return BigDecimal.ZERO;
}
return null;
}
use of jakarta.validation.constraints.PositiveOrZero in project hibernate-validator by hibernate.
the class NegativePositiveValidatorForStringTest method testIsValidPositiveOrZeroValidator.
@Test
public void testIsValidPositiveOrZeroValidator() {
ConstraintAnnotationDescriptor.Builder<PositiveOrZero> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(PositiveOrZero.class);
descriptorBuilder.setMessage("{validator.positiveOrZero}");
PositiveOrZero m = descriptorBuilder.build().getAnnotation();
PositiveOrZeroValidatorForCharSequence constraint = new PositiveOrZeroValidatorForCharSequence();
constraint.initialize(m);
assertTrue(constraint.isValid(null, null));
assertTrue(constraint.isValid("15", null));
assertTrue(constraint.isValid("15.0", null));
assertTrue(constraint.isValid("0", null));
assertFalse(constraint.isValid("-10", null));
assertFalse(constraint.isValid("-14.99", null));
// number format exception
assertFalse(constraint.isValid("15l", null));
}
Aggregations