Each class
An annotation that checks every element of a list or set, or every value of a map, against constraints.
Use it for rules about the items rather than the collection: each
answer non-blank, each score at least 0. Jakarta writes these on the
type argument (List<@NotBlank String>); Dart has no annotations
there. A null collection is skipped, and a value that is not a
collection or map throws a ConstraintDeclarationException.
A list element is reported as answers[1].<list element> (field error
on answers[1]), another iterable's as tags[].<iterable element>,
and a map value as scores[math].<map value>. Use EachKey for map
keys, and @Valid() to check the constraints inside element objects.
// Short, non-blank answers, and no negative scores.
@Introspected()
class Survey {
@Each([NotBlank(), Size(max: 20)])
List<String> answers = [];
@Each([Min(0)])
Map<String, int> scores = {};
}
Spring (Java):
class Survey {
private List<@NotBlank @Size(max = 20) String> answers;
private Map<String, @Min(0) Integer> scores;
}
Constructors
-
Each(List<
Constraint> constraints) -
Checks
constraintson every element or map value.const
Properties
-
constraints
→ List<
Constraint> -
The constraints each element must meet, such as
[NotBlank(), Size(max: 20)].final - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited