Class IntegerStringValidator

java.lang.Object
jp.ecuacion.lib.validation.constraints.IntegerStringValidator
All Implemented Interfaces:
jakarta.validation.ConstraintValidator<IntegerString, String>

public class IntegerStringValidator extends Object implements jakarta.validation.ConstraintValidator<IntegerString, String>
Provides the validation logic for IntegerString.
  • Constructor Details

    • IntegerStringValidator

      public IntegerStringValidator()
      Constructs a new instance.
  • Method Details

    • initialize

      public void initialize(IntegerString constraintAnnotation)
      Initializes an instance.
      Specified by:
      initialize in interface jakarta.validation.ConstraintValidator<IntegerString, String>
    • isValid

      public boolean isValid(String value, jakarta.validation.ConstraintValidatorContext context)
      Checks if a string is convertible to Integer.

      a string is valid if the value is blank or Integer.valueOf() does not throw exception.

      comma-separated value is acceptable. This validator removes comma before check. This does not check the positions of the commas are correct.

      Valid strings are: "123", "123,456", "12,3,4,56"

      null is valid following to the specification of Jakarta EE.

      empty ("") is also valid.
      Blank is allowed because it's supposed to be used for fields in record, which accepts values from external. HTML (and maybe others) cannot tell difference between blank and null for number values. Otherwise we also want the information whether the empty value is submitted (=blank) or not (=null).

      Specified by:
      isValid in interface jakarta.validation.ConstraintValidator<IntegerString, String>