Class AvroSchemaParser<U>

  • Type Parameters:
    U - The type of the data container
    All Implemented Interfaces:
    SchemaParser<org.apache.avro.Schema,​U>
    Direct Known Subclasses:
    DereferencedAvroSchemaParser

    public class AvroSchemaParser<U>
    extends Object
    implements SchemaParser<org.apache.avro.Schema,​U>
    An implementation of SchemaParser specifically for Avro schemas. This parser handles the parsing, validation, and resolution of Avro schemas, including complex schemas with nested types and references to other schemas. It supports extracting schemas from Avro records and managing schema dependencies.
    • Constructor Detail

      • AvroSchemaParser

        public AvroSchemaParser()
        Constructs a new AvroSchemaParser.
    • Method Detail

      • parse

        public ParsedSchema<org.apache.avro.Schema> parse​(byte[] rawSchemaBytes,
                                                          Map<String,​byte[]> references)
        Parses an Avro schema from a byte array, considering any referenced schemas.
        Specified by:
        parse in interface SchemaParser<org.apache.avro.Schema,​U>
        Parameters:
        rawSchemaBytes - 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 Avro schema
        Throws:
        UncheckedIOException - if there's an issue parsing the schema
      • getSchemaFromData

        public ParsedSchema<org.apache.avro.Schema> getSchemaFromData​(Record<U> 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<org.apache.avro.Schema,​U>
        Parameters:
        data - The record from which to extract the schema.
        Returns:
        A ParsedSchema containing both the raw schema (as bytes) and the parsed schema.
      • artifactType

        public String artifactType()
        Description copied from interface: SchemaParser
        Retrieves the artifact type of the schema parser.
        Specified by:
        artifactType in interface SchemaParser<org.apache.avro.Schema,​U>
        Returns:
        The artifact type of the schema parser.