Class UnionTypeValidator

  • All Implemented Interfaces:
    SimpleValidator<Object>

    public class UnionTypeValidator
    extends Validator
    Union Types An array of two or more simple validators definitions. Each item in the array MUST be a simple validators definition or a schema. The instance value is valid if it is of the same validators as one of the simple validators definitions, or valid by one of the schemas, in the array.

    For example, a schema that defines if an instance can be a string or a number would be:

    {"type":["string","number"]}
    See Also:
    type
    • Constructor Detail

      • UnionTypeValidator

        public UnionTypeValidator​(Map<String,​Object> schema,
                                  List<String> jsonPointer)
        Create a union type validator.
        Parameters:
        schema - The schema.
        jsonPointer - The pointers.
    • Method Detail

      • validate

        public void validate​(Object node,
                             JsonPointer at,
                             ErrorHandler handler)
                      throws SchemaException
        Validates the node value against the embedded schema object.

        The selected error handler defines the behaviour of the validator. The FailFastErrorHandler throws exception at firs violation. Other customised ErrorHandler can collect all exceptions and after the validation the examination of the handler contains the final result.

        Parameters:
        node - value to validate
        at - JSONPath of the node. null means it's the root node
        handler - customised error handler like FailFastErrorHandler
        Throws:
        SchemaException - when the node violates with the schema