@Required annotation

back to index

Action

Marks a field as required, meaning that empty values and nulls are not accepted.

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

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 int intField=22;

@Required
private Object objectField;

@Required
private String stringField;

@Required(allowEmpty=true)
private String stringFieldEmptyAllowed;

@Required
private List<String> myList;

@Required
private String[] myArray;

@Required
private Collection<String> myCollection;