Class MapSchema
java.lang.Object
org.pipservices3.commons.validate.Schema
org.pipservices3.commons.validate.MapSchema
- Direct Known Subclasses:
FilterParamsSchema
Schema to validate maps.
### Example ###
MapSchema schema = new MapSchema(TypeCode.String, TypeCode.Integer);
schema.validate({ "key1": "A", "key2": "B" }); // Result: no errors
schema.validate({ "key1": 1, "key2": 2 }); // Result: element type mismatch
schema.validate(new int[]{ 1, 2, 3 }); // Result: type mismatch
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of validation schema.Creates a new instance of validation schema and sets its values.Creates a new instance of validation schema and sets its values. -
Method Summary
Modifier and TypeMethodDescriptionGets the type of map keys.Gets the type of map values.protected void
performValidation
(String path, Object value, List<ValidationResult> results) Validates a given value against the schema and configured validation rules.void
setKeyType
(Object value) Sets the type of map keys.void
setValueType
(Object value) Sets the type of map values.Methods inherited from class org.pipservices3.commons.validate.Schema
getRules, isRequired, makeOptional, makeRequired, performTypeValidation, setRequired, setRules, validate, validateAndThrowException, validateAndThrowException, withRule
-
Constructor Details
-
MapSchema
public MapSchema()Creates a new instance of validation schema. -
MapSchema
Creates a new instance of validation schema and sets its values.- Parameters:
keyType
- a type of map keys. Null means that keys may have any type.valueType
- a type of map values. Null means that values may have any type.- See Also:
-
MapSchema
Creates a new instance of validation schema and sets its values.- Parameters:
keyType
- a type of map keys. Null means that keys may have any type.valueType
- a type of map values. Null means that values may have any type.required
- (optional) true to always require non-null values.rules
- (optional) a list with validation rules.
-
-
Method Details
-
getKeyType
Gets the type of map keys. Null means that keys may have any type.- Returns:
- the type of map keys.
-
setKeyType
Sets the type of map keys. Null means that keys may have any type.- Parameters:
value
- a type of map keys.
-
getValueType
Gets the type of map values. Null means that values may have any type.- Returns:
- the type of map values.
-
setValueType
Sets the type of map values. Null means that values may have any type.- Parameters:
value
- a type of map values.
-
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.
-