Package io.modelcontextprotocol.spec
Class DefaultJsonSchemaValidator
java.lang.Object
io.modelcontextprotocol.spec.DefaultJsonSchemaValidator
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.modelcontextprotocol.spec.JsonSchemaValidator
JsonSchemaValidator.ValidationResponse -
Constructor Summary
ConstructorsConstructorDescriptionDefaultJsonSchemaValidator(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the schema cache.protected StringgenerateCacheKey(Map<String, Object> schema) Generates a cache key for the given schema map.intReturns the current size of the schema cache.Validates the structured content against the provided JSON schema.
-
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:JsonSchemaValidatorValidates the structured content against the provided JSON schema.- Specified by:
validatein interfaceJsonSchemaValidator- 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
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
-