Class PropertySchema

java.lang.Object
org.pipservices3.commons.validate.Schema
org.pipservices3.commons.validate.PropertySchema

public class PropertySchema extends Schema
Schema to validate object properties

### Example ###

 
 ObjectSchema schema = new ObjectSchema().withProperty(new PropertySchema("id", TypeCode.String));

 schema.validate(Map.of("id", "1", "name" ,"ABC" ));	// Result: no errors
 schema.validate(Map.of( "name", "ABC" ));                    // Result: no errors
 schema.validate(Map.of( "id", 1, "name", "ABC" ));	// Result: id type mismatch
 
 
See Also:
  • Constructor Details

    • PropertySchema

      public PropertySchema()
      Creates a new validation schema.
    • PropertySchema

      public PropertySchema(String name, Object type)
      Creates a new validation schema and sets its values.
      Parameters:
      name - (optional) a property name
      type - (optional) a property type
      See Also:
    • PropertySchema

      public PropertySchema(String name, Object type, Boolean required, List<IValidationRule> rules)
      Creates a new validation schema and sets its values.
      Parameters:
      name - (optional) a property name
      type - (optional) a property type
      required - (optional) true to always require non-null values.
      rules - (optional) a list with validation rules.
      See Also:
  • Method Details

    • getName

      public String getName()
      Gets the property name.
      Returns:
      the property name.
    • setName

      public void setName(String value)
      Sets the property name.
      Parameters:
      value - a new property name.
    • getType

      public Object getType()
      Gets the property type.
      Returns:
      the property type.
    • setType

      public void setType(Object value)
      Sets a new property type. The type can be defined as type, type name or [[TypeCode]]
      Parameters:
      value - a new property type.
    • 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.