java.lang.Object
tools.jackson.dataformat.avro.AvroSchema
All Implemented Interfaces:
tools.jackson.core.FormatSchema

public class AvroSchema extends Object implements tools.jackson.core.FormatSchema
Wrapper for Schema information needed to encode and decode Avro-format data.
  • Field Details

    • TYPE_ID

      public static final String TYPE_ID
      Format type id used by Jackson components to refer to Avro Format.
      See Also:
    • _writerSchema

      protected final org.apache.avro.Schema _writerSchema
      Schema that was used for writing the data to decode; for simple instance used for reading as well (reader schema).
    • _reader

      protected final AtomicReference<AvroStructureReader> _reader
      Lazily instantiated value reader for this schema.
  • Constructor Details

    • AvroSchema

      public AvroSchema(org.apache.avro.Schema asch)
  • Method Details

    • withReaderSchema

      public AvroSchema withReaderSchema(AvroSchema readerSchema) throws tools.jackson.databind.DatabindException
      Method that will consider this schema instance (used as so-called "Writer Schema"), and specified "Reader Schema" instance, and will either construct a new schema with appropriate translations, to use for reading (if reader and writer schemas are not same); or, if schemas are the same, return `this`.

      Note that neither `this` instance nor `readerSchema` is ever modified: if an altered version is needed, a new schema object will be constructed.

      NOTE: this is a relatively expensive operation due to validation (although significant part of cost is deferred until the first call to getReader()) so it is recommended that these instances are reused whenever possible.

      Parameters:
      readerSchema - "Reader Schema" to use (in Avro terms): schema that specified how reader wants to see the data; specifies part of translation needed along with this schema (which would be "Writer Schema" in Avro terms).
      Throws:
      tools.jackson.databind.DatabindException - If given reader schema is incompatible with (writer-) schema this instance was constructed with,
    • withUnsafeReaderSchema

      public AvroSchema withUnsafeReaderSchema(AvroSchema readerSchema) throws tools.jackson.databind.DatabindException
      Similar to withReaderSchema(tools.jackson.dataformat.avro.AvroSchema) but will NOT verify compatibility of schemas: this means that certain problems (such as missing default value for a newly added field) that would be caught at construction may be surfaced later when using schema. This is, however, sometimes necessary to work around potential BUT NOT ACTUAL problems.
      Throws:
      tools.jackson.databind.DatabindException
    • getSchemaType

      public String getSchemaType()
      Specified by:
      getSchemaType in interface tools.jackson.core.FormatSchema
    • getAvroSchema

      public org.apache.avro.Schema getAvroSchema()
      Accessor for "writer schema" contained in this instance.
    • getReader

      public AvroStructureReader getReader()
    • _constructReader

      protected AvroStructureReader _constructReader()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object