Package com.solace.serdes.jsonschema
Class JsonSchemaParser<T>
- java.lang.Object
-
- com.solace.serdes.jsonschema.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 Summary
Constructors Constructor Description JsonSchemaParser()
Constructs a new JsonSchemaParser with default configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
artifactType()
Retrieves the artifact type of the schema parser.ParsedSchema<com.networknt.schema.JsonSchema>
getSchemaFromData(Record<T> data)
Extracts the schema from a given data record.ParsedSchema<com.networknt.schema.JsonSchema>
getSchemaFromLocation(String location)
Retrieves a schema from a specified location in the Java classpath.ParsedSchema<com.networknt.schema.JsonSchema>
parse(byte[] rawSchema, Map<String,byte[]> references)
Parses a raw schema from a byte array, considering any referenced schemas.boolean
supportsGetSchemaFromData()
Flag that indicates ifSchemaParser.getSchemaFromData(Record)
is implemented or not.boolean
supportsGetSchemaFromLocation()
Indicates that this parser supports retrieving schemas from classpath resources.
-
-
-
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 interfaceSchemaParser<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 interfaceSchemaParser<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.
-
supportsGetSchemaFromData
public boolean supportsGetSchemaFromData()
Description copied from interface:SchemaParser
Flag that indicates ifSchemaParser.getSchemaFromData(Record)
is implemented or not.- Specified by:
supportsGetSchemaFromData
in interfaceSchemaParser<com.networknt.schema.JsonSchema,T>
- Returns:
- true if
SchemaParser.getSchemaFromData(Record)
is implemented, false otherwise.
-
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 interfaceSchemaParser<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 interfaceSchemaParser<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 interfaceSchemaParser<com.networknt.schema.JsonSchema,T>
- Returns:
- The artifact type of the schema parser.
-
-