org.javalid.annotations.validation
Annotation Type ExactLength


@Target(value={METHOD,FIELD})
@Retention(value=RUNTIME)
@Documented
public @interface ExactLength

Checks if annotated method/field returns the exact length of this annotation. Can be annotated on fields or methods returning String, StringBuffer or StringBuilder.

Since:
1.2
Version:
1.0
Author:
M.Reuvers

Required Element Summary
 long value
          The exact length a field/methods value must have.
 
Optional Element Summary
 java.lang.String[] applyToGroups
          Specify for which groups this annotation must be applied.
 java.lang.String charSet
          Relevant only if countAs() has been set to 'byte', then this property determines how the String is converted to bytes (using this charset).
 java.lang.String countAs
          Tells how the length must be determined.
 java.lang.String customCode
          Optional custom code (property from a properties file).
 boolean globalMessage
          If this annotation's message must be added as global message instead of real validation path.
 

Element Detail

value

public abstract long value
The exact length a field/methods value must have.

countAs

public abstract java.lang.String countAs
Tells how the length must be determined. By default it does a default length() on a String and counts the characters (this was and still is the default). You can set it to "byte" instead to assure it gets it as bytes and then do a byte count. This may be useful for database character fields that are defined in bytes.

If byte is specified you may also need to override the characterset, it defaults to UTF-8 (when converting to bytes), set charSet in that case.

Chose char or byte, defaults to char.

Default:
"char"

charSet

public abstract java.lang.String charSet
Relevant only if countAs() has been set to 'byte', then this property determines how the String is converted to bytes (using this charset). Defaults to UTF-8.

Default:
"UTF-8"

applyToGroups

public abstract java.lang.String[] applyToGroups
Specify for which groups this annotation must be applied. By default if you annotate without this variable, the annotation is applied for any group on that method (which is what you usually want). However by specifying the exact groups you can turn on/off a validation on a method depending on the group you validate.

Defaults to JvGroup.GROUP_APPLY_ALL

Default:
"_all_"

customCode

public abstract java.lang.String customCode
Optional custom code (property from a properties file). If set, this one is used instead of the default one specified in MessageCodes for annotated method/field.

This way you can override the default message if needed.

Default:
""

globalMessage

public abstract boolean globalMessage
If this annotation's message must be added as global message instead of real validation path. Defaults to false (thus will be added with validation path if invalid).

Default:
false