Annotation Interface Required
For CharSequence objects (e.g. regular String objects), use allowBlank to allow empty or whitespace-only
Strings. It does not make sense to set allowEmpty to true but leave allowBlank as false, so in general when
annotating CharSequence objects, setting allowBlank to true is preferred, though it is also correct to
set both allowBlank and allowEmpty to true.
For Collection and Map objects, allowBlank has no effect, but allowEmpty
will cause empty collections and maps to be considered valid.
For any other type of object, only allowEmpty has any effect. If you have a custom object that has a public method
named isEmpty that has no arguments and returns boolean, this validator will attempt to invoke
that method reflectively and use its return value to determine whether the object is empty or not.
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether to allow an object that is aCharSequenceto be blank, usingStringUtils.isBlank(CharSequence)to perform the check.booleanWhether to allow an object to be "empty".Class<?>[]Class<? extends jakarta.validation.Payload>[]
-
Element Details
-
message
String message- Default:
- "{org.kiwiproject.validation.Required.message}"
-
groups
Class<?>[] groups- Default:
- {}
-
payload
Class<? extends jakarta.validation.Payload>[] payload- Default:
- {}
-
allowBlank
boolean allowBlankWhether to allow an object that is aCharSequenceto be blank, usingStringUtils.isBlank(CharSequence)to perform the check.This only applies to
CharSequenceobjects. All other (non-null) objects are always considered as not blank.- Returns:
- true to allow a
CharSequenceto be blank, false to consider blankCharSequenceas invalid
- Default:
- false
-
allowEmpty
boolean allowEmptyWhether to allow an object to be "empty". For String values, just checks the value itself. For anything else, attempts to find and call anisEmpty()method which allow this annotation to work on other types of objects, for example onCollectionobjects.- Returns:
- true to allow an object to be empty, false otherwise
- Default:
- false
-