Class MapSchema

java.lang.Object
org.pipservices3.commons.validate.Schema
org.pipservices3.commons.validate.MapSchema
Direct Known Subclasses:
FilterParamsSchema

public class MapSchema extends Schema
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 Details

    • MapSchema

      public MapSchema()
      Creates a new instance of validation schema.
    • MapSchema

      public MapSchema(Object keyType, Object valueType)
      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

      public MapSchema(Object keyType, Object valueType, Boolean required, List<IValidationRule> rules)
      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

      public Object getKeyType()
      Gets the type of map keys. Null means that keys may have any type.
      Returns:
      the type of map keys.
    • setKeyType

      public void setKeyType(Object value)
      Sets the type of map keys. Null means that keys may have any type.
      Parameters:
      value - a type of map keys.
    • getValueType

      public Object getValueType()
      Gets the type of map values. Null means that values may have any type.
      Returns:
      the type of map values.
    • setValueType

      public void setValueType(Object value)
      Sets the type of map values. Null means that values may have any type.
      Parameters:
      value - a type of map values.
    • performValidation

      protected void performValidation(String path, Object value, List<ValidationResult> results)
      Validates a given value against the schema and configured validation rules.
      Overrides:
      performValidation in class Schema
      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.