Class JsonSchemaParser<T>

  • Type Parameters:
    T - The type of object this parser works with
    All Implemented Interfaces:
    SchemaParser<com.networknt.schema.JsonSchema,​T>

    public class JsonSchemaParser<T>
    extends Object
    implements SchemaParser<com.networknt.schema.JsonSchema,​T>
    Parser for JSON Schema.

    This class implements the SchemaParser interface for JSON Schemas, providing functionality to parse raw schema bytes into JsonSchema objects. It handles schema references and supports JSON Schema Draft 7.

    • Constructor Detail

      • JsonSchemaParser

        public JsonSchemaParser()
        Constructs a new JsonSchemaParser with default configuration.
    • Method Detail

      • parse

        public ParsedSchema<com.networknt.schema.JsonSchema> parse​(byte[] rawSchema,
                                                                   Map<String,​byte[]> references)
        Description copied from interface: SchemaParser
        Parses a raw schema from a byte array, considering any referenced schemas.
        Specified by:
        parse in interface SchemaParser<com.networknt.schema.JsonSchema,​T>
        Parameters:
        rawSchema - Raw schema content as byte array.
        references - A map of referenced schemas, where the key is the reference name and the value is the raw schema content as a byte array.
        Returns:
        A parsed schema representation.
      • getSchemaFromData

        public ParsedSchema<com.networknt.schema.JsonSchema> getSchemaFromData​(Record<T> data)
        Description copied from interface: SchemaParser
        Extracts the schema from a given data record. This method is particularly useful for artifact types like AVRO, where the schema can be extracted directly from the Java object.
        Specified by:
        getSchemaFromData in interface SchemaParser<com.networknt.schema.JsonSchema,​T>
        Parameters:
        data - The record from which to extract the schema.
        Returns:
        A ParsedSchema containing both the raw schema (as bytes) and the parsed schema.
      • getSchemaFromLocation

        public ParsedSchema<com.networknt.schema.JsonSchema> getSchemaFromLocation​(String location)
        Retrieves a schema from a specified location in the Java classpath. This implementation loads the schema resource using the current thread's context class loader and parses it into a JsonSchema.
        Specified by:
        getSchemaFromLocation in interface SchemaParser<com.networknt.schema.JsonSchema,​T>
        Parameters:
        location - The resource path on the classpath from which to load the schema.
        Returns:
        A ParsedSchema containing both the raw schema (as bytes) and the parsed JsonSchema.
      • supportsGetSchemaFromLocation

        public boolean supportsGetSchemaFromLocation()
        Indicates that this parser supports retrieving schemas from classpath resources.
        Specified by:
        supportsGetSchemaFromLocation in interface SchemaParser<com.networknt.schema.JsonSchema,​T>
        Returns:
        true, as this implementation supports loading schemas from the classpath.
      • artifactType

        public String artifactType()
        Description copied from interface: SchemaParser
        Retrieves the artifact type of the schema parser.
        Specified by:
        artifactType in interface SchemaParser<com.networknt.schema.JsonSchema,​T>
        Returns:
        The artifact type of the schema parser.