Annotation Type Range


  • @Documented
    @Constraint(validatedBy=RangeValidator.class)
    @Target({METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER,TYPE_USE})
    @Retention(RUNTIME)
    public @interface Range
    The annotated element must be in the specified range, which can include both a minimum and maximum, only a minimum, or only a maximum. When only minimum or maximum is specified, the range is open-ended on the non-specified side. For example, if only a minimum is specified then there is no maximum applied in the constraint validation.

    Null values are considered valid by default, but you can change this behavior using the allowNull() property.

    Use min() and max() to specify the minimum and maximum values allowed in the range. These are inclusive values, e.g. for a range with a minimum of 5 and maximum of 10, the values 5 and 10 are considered as part of the range.

    Use the minLabel() and maxLabel() to specify custom labels to use in place of the min and max values. This is useful in cases where the min and max are large numbers or when validating date/time values where the min and max are specified as milliseconds since the epoch.

    The supported types are:

    • byte, short, int, long, and their respective wrapper types
    • float, double, and their respective wrapper types
    • BigDecimal
    • BigInteger
    • Date, using epoch millis for the min and max values
    • Instant, using epoch millis for the min and max values
    • JSON, using JSON to define the min and max values
    While float and double are supported, be aware of the possibility for rounding errors when values are near the range bounds. The comparisons use Float.compareTo(Float) and Double.compareTo(Double).
    • Element Detail

      • message

        String message
        Default:
        "{org.kiwiproject.validation.Range.between.message}"
      • groups

        Class<?>[] groups
        Default:
        {}
      • payload

        Class<? extends javax.validation.Payload>[] payload
        Default:
        {}
      • allowNull

        boolean allowNull
        Whether to consider null as valid. The default is true.
        Returns:
        true to consider null as valid
        Default:
        true
      • min

        String min
        Returns:
        the minimum allowed value for this range
        Default:
        ""
      • minLabel

        String minLabel
        Returns:
        the label to be used in error messages in place of the minimum value, e.g. "ten" instead of 10
        Default:
        ""
      • max

        String max
        Returns:
        the maximum allowed value for this range
        Default:
        ""
      • maxLabel

        String maxLabel
        Returns:
        the label to be used in error messages in place of the maximum value, e.g. "ten" instead of 10
        Default:
        ""