Class Validator

java.lang.Object
dev.harrel.jsonschema.Validator

public final class Validator extends Object
Main class for performing JSON schema validation. It can be created via ValidatorFactory. Configuration of Validator is immutable. It uses schema registry to keep track of all the registered schemas, which are registered either by registerSchema(String) method (and its overloads) or by SchemaResolver resolution.
See Also:
  • Method Details

    • registerSchema

      public URI registerSchema(String rawSchema)
      Registers schema and generates URI for it.
      Parameters:
      rawSchema - string representation of schema JSON
      Returns:
      automatically generated URI for the registered schema OR value of $id keyword in root schema if present
    • registerSchema

      public URI registerSchema(Object schemaProviderNode)
      Registers schema and generates URI for it.
      Parameters:
      schemaProviderNode - object representing schema JSON for currently set JsonNodeFactory. E.g. com.fasterxml.jackson.databind.JsonNode for default JsonNodeFactory (JacksonNode.Factory)
      Returns:
      automatically generated URI for the registered schema OR value of $id keyword in root schema if present
    • registerSchema

      public URI registerSchema(JsonNode schemaNode)
      Registers schema and generates URI for it.
      Parameters:
      schemaNode - JsonNode schema JSON, which could be created via JsonNodeFactory
      Returns:
      automatically generated URI for the registered schema OR value of $id keyword in root schema if present
    • registerSchema

      public URI registerSchema(URI uri, String rawSchema)
      Registers schema at specified URI.
      Parameters:
      uri - schema URI
      rawSchema - string representation of schema JSON
      Returns:
      URI provided by user OR value of $id keyword in root schema if present
    • registerSchema

      public URI registerSchema(URI uri, Object schemaProviderNode)
      Registers schema at specified URI.
      Parameters:
      uri - schema URI
      schemaProviderNode - object representing schema JSON for currently set JsonNodeFactory. E.g. com.fasterxml.jackson.databind.JsonNode for default JsonNodeFactory (JacksonNode.Factory)
      Returns:
      URI provided by user OR value of $id keyword in root schema if present
    • registerSchema

      public URI registerSchema(URI uri, JsonNode schemaNode)
      Registers schema at specified URI.
      Parameters:
      uri - schema URI
      schemaNode - JsonNode schema JSON, which could be created via JsonNodeFactory
      Returns:
      URI provided by user OR value of $id keyword in root schema if present
    • validate

      public Validator.Result validate(URI schemaUri, String rawInstance)
      Validates instance JSON against schema resolved from provided URI.
      Parameters:
      schemaUri - URI of schema to use for validation
      rawInstance - string representation of instance JSON
      Returns:
      validation result
    • validate

      public Validator.Result validate(URI schemaUri, Object instanceProviderNode)
      Validates instance JSON against schema resolved from provided URI.
      Parameters:
      schemaUri - URI of schema to use for validation
      instanceProviderNode - object representing instance JSON for currently set JsonNodeFactory. E.g. com.fasterxml.jackson.databind.JsonNode for default JsonNodeFactory (JacksonNode.Factory)
      Returns:
      validation result
    • validate

      public Validator.Result validate(URI schemaUri, JsonNode instanceNode)
      Validates instance JSON against a root schema resolved from provided URI.
      Parameters:
      schemaUri - URI of a root schema to use for validation
      instanceNode - JsonNode instance JSON, which could be created via JsonNodeFactory
      Returns:
      validation result