Class DefaultJsonSchemaValidator

java.lang.Object
io.modelcontextprotocol.spec.DefaultJsonSchemaValidator
All Implemented Interfaces:
JsonSchemaValidator

public class DefaultJsonSchemaValidator extends Object implements JsonSchemaValidator
Default implementation of the JsonSchemaValidator interface. This class provides methods to validate structured content against a JSON schema. It uses the NetworkNT JSON Schema Validator library for validation.
Author:
Christian Tzolov
  • Constructor Details

    • DefaultJsonSchemaValidator

      public DefaultJsonSchemaValidator()
    • DefaultJsonSchemaValidator

      public DefaultJsonSchemaValidator(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
  • Method Details

    • validate

      public JsonSchemaValidator.ValidationResponse validate(Map<String,Object> schema, Map<String,Object> structuredContent)
      Description copied from interface: JsonSchemaValidator
      Validates the structured content against the provided JSON schema.
      Specified by:
      validate in interface JsonSchemaValidator
      Parameters:
      schema - The JSON schema to validate against.
      structuredContent - The structured content to validate.
      Returns:
      A ValidationResponse indicating whether the validation was successful or not.
    • generateCacheKey

      protected String generateCacheKey(Map<String,Object> schema)
      Generates a cache key for the given schema map.
      Parameters:
      schema - the schema map
      Returns:
      a cache key string
    • clearCache

      public void clearCache()
      Clears the schema cache. Useful for testing or memory management.
    • getCacheSize

      public int getCacheSize()
      Returns the current size of the schema cache.
      Returns:
      the number of cached schemas