Annotation Type Required
-
@Documented @Constraint(validatedBy=RequiredValidator.class) @Target({METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER,TYPE_USE}) @Retention(RUNTIME) public @interface Required
Ensures that a value is provided (i.e. not null). Null values are always considered invalid. You can refine the behavior by allowing blank or empty Strings, collections, maps, or other types of object to be considered valid.For
CharSequenceobjects (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 annotatingCharSequenceobjects, setting allowBlank to true is preferred, though it is also correct to set both allowBlank and allowEmpty to true.For
CollectionandMapobjects, 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
isEmptythat has no arguments and returnsboolean, 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 Elements Modifier and Type Optional Element Description booleanallowBlankWhether to allow an object that is aCharSequenceto be blank, usingStringUtils.isBlank(CharSequence)to perform the check.booleanallowEmptyWhether to allow an object to be "empty".Class<?>[]groupsStringmessageClass<? extends javax.validation.Payload>[]payload
-
-
-
Element Detail
-
message
String message
- Default:
- "{org.kiwiproject.validation.Required.message}"
-
-
-
groups
Class<?>[] groups
- Default:
- {}
-
-
-
payload
Class<? extends javax.validation.Payload>[] payload
- Default:
- {}
-
-
-
allowBlank
boolean allowBlank
Whether 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 allowEmpty
Whether 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
-
-