Class DefaultJsonSchemaValidator
java.lang.Object
io.modelcontextprotocol.json.schema.jackson3.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:
- Filip Hrisafov
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.modelcontextprotocol.json.schema.JsonSchemaValidator
JsonSchemaValidator.ValidationResponse -
Constructor Summary
ConstructorsConstructorDescriptionDefaultJsonSchemaValidator(tools.jackson.databind.json.JsonMapper jsonMapper) -
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.validateSchema(Map<String, Object> schema) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.modelcontextprotocol.json.schema.JsonSchemaValidator
assertConforms
-
Constructor Details
-
DefaultJsonSchemaValidator
public DefaultJsonSchemaValidator() -
DefaultJsonSchemaValidator
public DefaultJsonSchemaValidator(tools.jackson.databind.json.JsonMapper jsonMapper)
-
-
Method Details
-
validate
public JsonSchemaValidator.ValidationResponse validate(Map<String, Object> schema, Object structuredContent) - Specified by:
validatein interfaceJsonSchemaValidator
-
validateSchema
- Specified by:
validateSchemain interfaceJsonSchemaValidator
-
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
-