public abstract class Schema extends JsonProperties
A schema may be one of:
SchemaBuilder
. The schema objects are
logically immutable.
There are only two mutating methods - setFields(List)
and
JsonProperties.addProp(String, String)
. The following restrictions apply on these
two methods.
setFields(List)
, can be called at most once. This method exists
in order to enable clients to build recursive schemas.
JsonProperties.addProp(String, String)
can be called with property names
that are not present already. It is not possible to change or delete an
existing property.
Modifier and Type | Class and Description |
---|---|
static class |
Schema.Field
A field within a record.
|
static class |
Schema.Parser
A parser for JSON-format schemas.
|
static class |
Schema.Type
The type of a schema.
|
JsonProperties.Null
NULL_VALUE
Modifier and Type | Method and Description |
---|---|
void |
addAlias(String alias)
If this is a record, enum or fixed, add an alias.
|
void |
addAlias(String alias,
String space)
If this is a record, enum or fixed, add an alias.
|
void |
addProp(String name,
org.codehaus.jackson.JsonNode value)
Adds a property with the given name name and
value value.
|
void |
addProp(String name,
Object value) |
static Schema |
applyAliases(Schema writer,
Schema reader)
Rewrite a writer's schema using the aliases from a reader's schema.
|
static Schema |
create(Schema.Type type)
Create a schema for a primitive type.
|
static Schema |
createArray(Schema elementType)
Create an array schema.
|
static Schema |
createEnum(String name,
String doc,
String namespace,
List<String> values)
Create an enum schema.
|
static Schema |
createFixed(String name,
String doc,
String space,
int size)
Create a union schema.
|
static Schema |
createMap(Schema valueType)
Create a map schema.
|
static Schema |
createRecord(List<Schema.Field> fields)
Create an anonymous record schema.
|
static Schema |
createRecord(String name,
String doc,
String namespace,
boolean isError)
Create a named record schema.
|
static Schema |
createRecord(String name,
String doc,
String namespace,
boolean isError,
List<Schema.Field> fields)
Create a named record schema with fields already set.
|
static Schema |
createUnion(List<Schema> types)
Create a union schema.
|
static Schema |
createUnion(Schema... types)
Create a union schema.
|
boolean |
equals(Object o) |
Set<String> |
getAliases()
If this is a record, enum or fixed, return its aliases, if any.
|
String |
getDoc()
If this is a record, enum, or fixed, returns its docstring,
if available.
|
Schema |
getElementType()
If this is an array, returns its element type.
|
int |
getEnumOrdinal(String symbol)
If this is an enum, return a symbol's ordinal value.
|
List<String> |
getEnumSymbols()
If this is an enum, return its symbols.
|
Schema.Field |
getField(String fieldname)
If this is a record, returns the Field with the
given name fieldName.
|
List<Schema.Field> |
getFields()
If this is a record, returns the fields in it.
|
int |
getFixedSize()
If this is fixed, returns its size.
|
String |
getFullName()
If this is a record, enum or fixed, returns its namespace-qualified name,
otherwise returns the name of the primitive type.
|
Integer |
getIndexNamed(String name)
If this is a union, return the branch with the provided full name.
|
LogicalType |
getLogicalType() |
String |
getName()
If this is a record, enum or fixed, returns its name, otherwise the name
of the primitive type.
|
String |
getNamespace()
If this is a record, enum or fixed, returns its namespace, if any.
|
Schema.Type |
getType()
Return the type of this schema.
|
List<Schema> |
getTypes()
If this is a union, returns its types.
|
Schema |
getValueType()
If this is a map, returns its value type.
|
boolean |
hasEnumSymbol(String symbol)
If this is an enum, returns true if it contains given symbol.
|
int |
hashCode() |
boolean |
isError()
Returns true if this record is an error type.
|
static Schema |
parse(File file)
Deprecated.
use
Schema.Parser instead. |
static Schema |
parse(InputStream in)
Deprecated.
use
Schema.Parser instead. |
static Schema |
parse(String jsonSchema)
Deprecated.
use
Schema.Parser instead. |
static Schema |
parse(String jsonSchema,
boolean validate)
Deprecated.
use
Schema.Parser instead. |
static org.codehaus.jackson.JsonNode |
parseJson(String s)
Deprecated.
|
void |
setFields(List<Schema.Field> fields)
If this is a record, set its fields.
|
String |
toString()
Render this as JSON.
|
String |
toString(boolean pretty)
Render this as JSON.
|
addProp, getJsonProp, getJsonProps, getObjectProp, getObjectProps, getProp, getProps
public static Schema create(Schema.Type type)
public void addProp(String name, org.codehaus.jackson.JsonNode value)
JsonProperties
addProp
in class JsonProperties
name
- The name of the property to addvalue
- The value for the property to addpublic void addProp(String name, Object value)
addProp
in class JsonProperties
public LogicalType getLogicalType()
public static Schema createRecord(List<Schema.Field> fields)
public static Schema createRecord(String name, String doc, String namespace, boolean isError)
public static Schema createRecord(String name, String doc, String namespace, boolean isError, List<Schema.Field> fields)
public static Schema createEnum(String name, String doc, String namespace, List<String> values)
public static Schema createFixed(String name, String doc, String space, int size)
public Schema.Type getType()
public Schema.Field getField(String fieldname)
public List<Schema.Field> getFields()
public void setFields(List<Schema.Field> fields)
public int getEnumOrdinal(String symbol)
public boolean hasEnumSymbol(String symbol)
public String getName()
public String getDoc()
public String getNamespace()
public String getFullName()
public void addAlias(String alias)
public void addAlias(String alias, String space)
public Set<String> getAliases()
public boolean isError()
public Schema getElementType()
public Schema getValueType()
public Integer getIndexNamed(String name)
public int getFixedSize()
public String toString(boolean pretty)
pretty
- if true, pretty-print JSON.public static Schema parse(File file) throws IOException
Schema.Parser
instead.file
- The file to read the schema from.IOException
- if there was trouble reading the contentsorg.codehaus.jackson.JsonParseException
- if the contents are invalidpublic static Schema parse(InputStream in) throws IOException
Schema.Parser
instead.in
- The input stream to read the schema from.IOException
- if there was trouble reading the contentsorg.codehaus.jackson.JsonParseException
- if the contents are invalidpublic static Schema parse(String jsonSchema)
Schema.Parser
instead.public static Schema parse(String jsonSchema, boolean validate)
Schema.Parser
instead.validate
- true if names should be validated, false if not.@Deprecated public static org.codehaus.jackson.JsonNode parseJson(String s)
Json.parseJson(String)
public static Schema applyAliases(Schema writer, Schema reader)
Copyright © 2009–2016 The Apache Software Foundation. All rights reserved.