Search in sources :

Example 1 with Positive

use of javax.validation.constraints.Positive in project jsonschema-generator by victools.

the class JavaxValidationModule method resolveNumberExclusiveMinimum.

/**
 * Determine a number type's minimum (exclusive) value.
 *
 * @param member the field or method to check
 * @return specified exclusive minimum value (or null)
 * @see DecimalMin
 * @see Positive
 */
protected BigDecimal resolveNumberExclusiveMinimum(MemberScope<?, ?> member) {
    DecimalMin decimalMinAnnotation = this.getAnnotationFromFieldOrGetter(member, DecimalMin.class, DecimalMin::groups);
    if (decimalMinAnnotation != null && !decimalMinAnnotation.inclusive()) {
        return new BigDecimal(decimalMinAnnotation.value());
    }
    Positive positiveAnnotation = this.getAnnotationFromFieldOrGetter(member, Positive.class, Positive::groups);
    if (positiveAnnotation != null) {
        return BigDecimal.ZERO;
    }
    return null;
}
Also used : Positive(javax.validation.constraints.Positive) DecimalMin(javax.validation.constraints.DecimalMin) BigDecimal(java.math.BigDecimal)

Example 2 with Positive

use of javax.validation.constraints.Positive in project jboot by yangfuhai.

the class PositiveInterceptor method intercept.

@Override
public void intercept(Invocation inv) {
    Parameter[] parameters = inv.getMethod().getParameters();
    for (int index = 0; index < parameters.length; index++) {
        Positive positive = parameters[index].getAnnotation(Positive.class);
        if (positive != null) {
            Object validObject = inv.getArg(index);
            if (validObject == null || ((Number) validObject).longValue() <= 0) {
                String reason = parameters[index].getName() + " is null or not positive at method: " + ClassUtil.buildMethodString(inv.getMethod());
                ValidUtil.throwValidException(parameters[index].getName(), positive.message(), reason);
            }
        }
    }
    inv.invoke();
}
Also used : Positive(javax.validation.constraints.Positive) Parameter(java.lang.reflect.Parameter)

Aggregations

Positive (javax.validation.constraints.Positive)2 Parameter (java.lang.reflect.Parameter)1 BigDecimal (java.math.BigDecimal)1 DecimalMin (javax.validation.constraints.DecimalMin)1