Package org.apache.avro
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) andinline
. 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 TypeMethodDescriptionstatic String
Format a schema with the specified format.Write the specified schema as a String.static SchemaFormatter
getInstance
(String name) Get the schema formatter for the specified format name with optional variant.
-
Method Details
-
getInstance
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
Format a schema with the specified format. Shorthand forgetInstance(name).format(schema)
.- Parameters:
name
- the name of the schema formatschema
- the schema to format- Returns:
- the formatted schema
- Throws:
AvroRuntimeException
- if the schema format is not supported- See Also:
-
format
Write the specified schema as a String.- Parameters:
schema
- the schema to write- Returns:
- the formatted schema
-