Interface Constraint<V>
-
- Type Parameters:
V
- value type
public interface Constraint<V>
Perform a validation on data upon load.- Since:
- 4.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Constraint.Factory<A extends Annotation,V>
Provider for a specific constraint given a field type.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static Constraint.Factory<Matches,String>
localizedPattern(ResourceBundle bundle)
Require values to match thepattern
provided.static Constraint.Factory<Matches,String>
pattern()
Require values to match thepattern
provided.static <T extends Annotation>
Constraint.Factory<T,Object>required()
Require a value to be present for fields marked with the annotationT
.void
validate(@Nullable V value)
Check if the provided deserialized value matches an expected condition.
-
-
-
Method Detail
-
validate
void validate(@Nullable V value) throws SerializationException
Check if the provided deserialized value matches an expected condition.- Parameters:
value
- value to test- Throws:
SerializationException
- if the value falls outside its constraint.- Since:
- 4.0.0
-
required
static <T extends Annotation> Constraint.Factory<T,Object> required()
Require a value to be present for fields marked with the annotationT
.- Type Parameters:
T
- marker annotation type- Returns:
- new constraint factory
- Since:
- 4.0.0
-
pattern
static Constraint.Factory<Matches,String> pattern()
Require values to match thepattern
provided.Upon failure, an error message will be taken from the annotation.
- Returns:
- factory providing matching pattern test
- Since:
- 4.0.0
-
localizedPattern
static Constraint.Factory<Matches,String> localizedPattern(ResourceBundle bundle)
Require values to match thepattern
provided.Upon failure, an error message will be taken from
bundle
with a key defined in the annotation.- Parameters:
bundle
- source for localized messages- Returns:
- factory providing matching pattern test
- Since:
- 4.0.0
-
-