@Required / @NotNull annotation

back to index

Action

Marks a field as required, meaning that empty values and nulls are not accepted. Both annotations have exactly the same effect. @NotNull is a convenience synonym for @Required.

Javadoc Ref :  Javadoc reference@Required

 Input Types 1
Object
 Output Types
Object
   

1Automatic conversion will take place if the provided input does not match any of the input classes, as described in the conversions part of the manual.

Arguments

allowEmpty

Specifies whether empty data (empty strings, empty arrays, etc) are allowed. Default is false

allowBlank
Specifies whether data composed entirely of blanks ( control characters or spaces) is allowed. Default is true.
message

Literal message to use if validation fails.

errorCode
Error code to use if validation fails.
messageKey
Message key to use if validation fails.

 

Example

@Required
private Object objectField;

@NotNull
private String stringField;

@Required(allowEmpty=true)
private String stringFieldEmptyAllowed;

@Required
private List<String> myList;

@Required
private String[] myArray;

@Required
private Collection<String> myCollection;