Class ArraySchema
java.lang.Object
org.pipservices3.commons.validate.Schema
org.pipservices3.commons.validate.ArraySchema
- Direct Known Subclasses:
ProjectionParamsSchema
Schema to validate arrays.
### Example ###
ArraySchema schema = new ArraySchema(TypeCode.String);
schema.validate(new String[]{"A", "B", "C"}); // Result: no errors
schema.validate(new int[] {1, 2, 3}); // Result: element type mismatch
schema.validate("A"); // Result: type mismatch
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of validation schema.ArraySchema
(Object valueType) Creates a new instance of validation schema and sets its values.ArraySchema
(Object valueType, boolean required, List<IValidationRule> rules) Creates a new instance of validation schema and sets its values. -
Method Summary
Modifier and TypeMethodDescriptionGets the type of array elements.protected void
performValidation
(String path, Object value, List<ValidationResult> results) Validates a given value against the schema and configured validation rules.void
setValueType
(Object value) Sets the type of array elements.Methods inherited from class org.pipservices3.commons.validate.Schema
getRules, isRequired, makeOptional, makeRequired, performTypeValidation, setRequired, setRules, validate, validateAndThrowException, validateAndThrowException, withRule
-
Constructor Details
-
ArraySchema
public ArraySchema()Creates a new instance of validation schema. -
ArraySchema
Creates a new instance of validation schema and sets its values.- Parameters:
valueType
- a type of array elements. Null means that elements may have any type.
-
ArraySchema
Creates a new instance of validation schema and sets its values.- Parameters:
valueType
- a type of array elements. Null means that elements may have any type.required
- (optional) true to always require non-null values.rules
- (optional) a list with validation rules.
-
-
Method Details
-
getValueType
Gets the type of array elements. Null means that elements may have any type.- Returns:
- the type of array elements.
-
setValueType
Sets the type of array elements. Null means that elements may have any type.- Parameters:
value
- a type of array elements.
-
performValidation
Validates a given value against the schema and configured validation rules.- Overrides:
performValidation
in classSchema
- Parameters:
path
- a dot notation path to the value.value
- a value to be validated.results
- a list with validation results to add new results.
-