Interface SchemaFormatter

All Known Implementing Classes:
CanonicalSchemaFormatterFactory, IdlSchemaFormatter, JsonSchemaFormatter

public interface SchemaFormatter
Interface and factory to format schemas to text.

Schema formats have a name, and optionally a variant (all lowercase). The Avro library supports a few formats out of the box:

json
Classic schema definition (which is a form of JSON). Supports the variants pretty (the default) and inline. Can be written as .avsc files. See the specification (Schema Declaration) for more details.
canonical
Parsing Canonical Form; this uniquely defines how Avro data is written. Used to generate schema fingerprints.
See the specification (Parsing Canonical Form for Schemas) for more details.
idl
IDL: a format that looks much like source code, and is arguably easier to read than JSON. Available when the module avro-idl is on the classpath. See IDL Language for more details.

Additional formats can be defined by implementing SchemaFormatterFactory.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    format(String name, Schema schema)
    Format a schema with the specified format.
    format(Schema schema)
    Write the specified schema as a String.
    Get the schema formatter for the specified format name with optional variant.
  • Method Details

    • getInstance

      static SchemaFormatter getInstance(String name)
      Get the schema formatter for the specified format name with optional variant.
      Parameters:
      name - a format with optional variant, for example "json/pretty", "canonical" or "idl"
      Returns:
      the schema formatter for the specified format
      Throws:
      AvroRuntimeException - if the schema format is not supported
    • format

      static String format(String name, Schema schema)
      Format a schema with the specified format. Shorthand for getInstance(name).format(schema).
      Parameters:
      name - the name of the schema format
      schema - the schema to format
      Returns:
      the formatted schema
      Throws:
      AvroRuntimeException - if the schema format is not supported
      See Also:
    • format

      String format(Schema schema)
      Write the specified schema as a String.
      Parameters:
      schema - the schema to write
      Returns:
      the formatted schema