Package org.apache.avro
Interface FormattedSchemaParser
- All Known Implementing Classes:
IdlSchemaParser
,JsonSchemaParser
public interface FormattedSchemaParser
Schema parser for a specific schema format.
The SchemaParser
class uses this interface, supporting text based
schema sources.
Implementations are located using a ServiceLoader
and must
therefore be threadsafe. See the ServiceLoader
class for details on
loading your implementation.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionparse
(ParseContext parseContext, URI baseUri, CharSequence formattedSchema) Parse schema definitions from a text based source.
-
Method Details
-
parse
Schema parse(ParseContext parseContext, URI baseUri, CharSequence formattedSchema) throws IOException, SchemaParseException Parse schema definitions from a text based source.
Notes for implementers:
- Schema definitions are expected not to be in the format the parser expects. So when the input clearly doesn't make sense (e.g., reading "/**" when expecting JSON), it is a good idea not to do anything (especially calling methods on the @code ParseContext}).
- The parameter
parseContext
is not thread-safe. - All named schema definitions that are parsed should be added to the
provided
ParseContext
. - Optionally, you may return a "main" schema. Some schema definitions have
one, for example the schema defined by the root of the JSON document in a
standard schema
definition. If unsure, return
null
. - If parsing fails, throw a
SchemaParseException
. This will let the parsing process recover and continue. - Throwing anything other than a
SchemaParseException
will abort the parsing process, so reserve that for rethrowing exceptions.
- Parameters:
parseContext
- the current parse context: all named schemata that are parsed should be added here, otherwise resolving schemata can fail; contains all previously known typesbaseUri
- the base location of the schema, ornull
if not knownformattedSchema
- the text of the schema definition(s) to parse- Returns:
- the main schema, if any
- Throws:
IOException
- when the schema cannot be readSchemaParseException
- when the schema cannot be parsed
-