Class JsonSchemaContentValidator

All Implemented Interfaces:
IResourceResolver, IContentValidator

public class JsonSchemaContentValidator extends AbstractContentValidator
Validates JSON content against a JSON schema.
  • Constructor Details

    • JsonSchemaContentValidator

      public JsonSchemaContentValidator(@NonNull Reader reader)
      Construct a new JSON schema validator using the provided reader to load the JSON schema.
      Parameters:
      reader - the JSON schema reader
    • JsonSchemaContentValidator

      public JsonSchemaContentValidator(@NonNull InputStream is)
      Construct a new JSON schema validator using the provided input stream to load the JSON schema.
      Parameters:
      is - the JSON schema input source
    • JsonSchemaContentValidator

      public JsonSchemaContentValidator(@NonNull org.json.JSONObject jsonSchema)
      Construct a new JSON schema validator using the provided JSON object for the JSON schema.
      Parameters:
      jsonSchema - the JSON schema
    • JsonSchemaContentValidator

      protected JsonSchemaContentValidator(@NonNull org.json.JSONTokener tokenizer)
      Construct a new JSON schema validator using the provided JSON tokenizer to load the schema.
      Parameters:
      tokenizer - the JSON schema token stream
    • JsonSchemaContentValidator

      protected JsonSchemaContentValidator(@NonNull org.everit.json.schema.Schema schema)
      Construct a new JSON schema validator using the preloaded JSON schema.
      Parameters:
      schema - the preloaded JSON schema
  • Method Details

    • validate

      public IValidationResult validate(InputStream is, URI resourceUri) throws IOException
      Description copied from interface: IContentValidator
      Validate the resource associated with the provided input stream is.
      Parameters:
      is - an input stream to access the resource
      resourceUri - the URI of the resource to validate
      Returns:
      the result of the validation
      Throws:
      IOException - if an error occurred while performing validation
    • validate

      @NonNull public IValidationResult validate(@NonNull org.json.JSONObject json, @NonNull URI resourceUri)
      Validate the provided JSON.
      Parameters:
      json - the JSON to validate
      resourceUri - the source URI for the JSON to validate
      Returns:
      the validation results
    • handleValidationException

      @NonNull protected Stream<JsonSchemaContentValidator.JsonValidationFinding> handleValidationException(@NonNull org.everit.json.schema.ValidationException exception, @NonNull URI resourceUri)
      Build validation findings from a validation exception.
      Parameters:
      exception - the JSON schema validation exception generated during schema validation representing the issue
      resourceUri - the resource the issue was found in
      Returns:
      the stream of findings