Class AvroSchemaHelper
java.lang.Object
tools.jackson.dataformat.avro.schema.AvroSchemaHelper
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstant used by native Avro Schemas for indicating more specific physical class of a value; referenced indirectly to reduce direct dependencies to the standard avro library.static final StringConstant used by native Avro Schemas for indicating more specific physical class of a array element; referenced indirectly to reduce direct dependencies to the standard avro library.static final StringConstant used by native Avro Schemas for indicating more specific physical class of a map key; referenced indirectly to reduce direct dependencies to the standard avro library.Default stringable classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.avro.SchemaaddAlias(org.apache.avro.Schema schema, tools.jackson.databind.introspect.AnnotatedClass annotations) Looks for@AvroAliasonbeanand adds it toschemaif it existsstatic org.apache.avro.Schemastatic org.apache.avro.SchemacreateEnumSchema(tools.jackson.databind.cfg.MapperConfig<?> config, tools.jackson.databind.JavaType enumType, tools.jackson.databind.introspect.AnnotatedClass annotations, List<String> values) Constructs a new enum schemastatic org.apache.avro.SchemaHelper method to enclose details of expressing best Avro Schema forUUID: 16-byte fixed-length binary (alternative would be basic variable length "bytes").static StringgetFullName(org.apache.avro.Schema schema) Returns the full name of a schema; This is similar toSchema.getFullName(), except that it properly handles namespaces for nested classesprotected static StringgetNamespace(Class<?> cls) protected static StringgetNamespace(tools.jackson.databind.JavaType type, tools.jackson.databind.introspect.AnnotatedClass annotations) static StringReturns the Avro type ID for a given typestatic StringgetTypeId(org.apache.avro.Schema schema) Returns the type ID for this schema, ornullif none is present.static StringgetTypeId(tools.jackson.databind.JavaType type) protected static StringgetTypeName(tools.jackson.databind.JavaType type) static org.apache.avro.SchemainitializeRecordSchema(tools.jackson.databind.cfg.MapperConfig<?> config, tools.jackson.databind.JavaType type, tools.jackson.databind.introspect.AnnotatedClass annotations) Initializes a record schema with metadata from the given class; this schema is returned in a non-finalized state, and still needs to have fields added to it.static booleanisStringable(tools.jackson.databind.introspect.AnnotatedClass type) Checks if a given type is "Stringable", that is one of the defaultSTRINGABLE_CLASSES, is anEnum, or is annotated with@Stringableand has a constructor that takes a single string argument capable of deserializing the output of itstoString()method.static ObjectjsonNodeToObject(tools.jackson.databind.JsonNode defaultJsonValue) static tools.jackson.databind.JsonNodenullNode()static org.apache.avro.SchemanumericAvroSchema(tools.jackson.core.JsonParser.NumberType type) static org.apache.avro.SchemanumericAvroSchema(tools.jackson.core.JsonParser.NumberType type, tools.jackson.databind.JavaType hint) static tools.jackson.databind.JsonNodeobjectToJsonNode(Object defaultValue) static tools.jackson.databind.JsonNodeparseDefaultValue(String defaultValue) Converts a default value represented as a string (such as from a schema specification) into a JsonNode for further handling.static org.apache.avro.SchemaparseJsonSchema(String json) Parses a JSON-formatted representation of a schemastatic org.apache.avro.SchemasimpleSchema(tools.jackson.databind.jsonFormatVisitors.JsonFormatTypes type, tools.jackson.databind.JavaType hint) static org.apache.avro.SchemastringableKeyMapSchema(tools.jackson.databind.JavaType mapType, tools.jackson.databind.JavaType keyType, org.apache.avro.Schema valueSchema) protected static <T> Tstatic org.apache.avro.SchematypedSchema(org.apache.avro.Schema.Type nativeType, tools.jackson.databind.JavaType javaType) Helper method for constructing type-tagged "native" Avro Schema instance.protected static org.apache.avro.SchemaunionWithNull(org.apache.avro.Schema otherSchema)
-
Field Details
-
AVRO_SCHEMA_PROP_CLASS
Constant used by native Avro Schemas for indicating more specific physical class of a value; referenced indirectly to reduce direct dependencies to the standard avro library.- See Also:
-
AVRO_SCHEMA_PROP_KEY_CLASS
Constant used by native Avro Schemas for indicating more specific physical class of a map key; referenced indirectly to reduce direct dependencies to the standard avro library.- See Also:
-
AVRO_SCHEMA_PROP_ELEMENT_CLASS
Constant used by native Avro Schemas for indicating more specific physical class of a array element; referenced indirectly to reduce direct dependencies to the standard avro library.- See Also:
-
STRINGABLE_CLASSES
Default stringable classes
-
-
Constructor Details
-
AvroSchemaHelper
public AvroSchemaHelper()
-
-
Method Details
-
isStringable
public static boolean isStringable(tools.jackson.databind.introspect.AnnotatedClass type) Checks if a given type is "Stringable", that is one of the defaultSTRINGABLE_CLASSES, is anEnum, or is annotated with@Stringableand has a constructor that takes a single string argument capable of deserializing the output of itstoString()method.- Parameters:
type- Type to check if it can be serialized to a Avro string schema- Returns:
trueif it can be stored in a string schema, otherwisefalse
-
getNamespace
protected static String getNamespace(tools.jackson.databind.JavaType type, tools.jackson.databind.introspect.AnnotatedClass annotations) -
getNamespace
-
getTypeName
-
unionWithNull
protected static org.apache.avro.Schema unionWithNull(org.apache.avro.Schema otherSchema) -
simpleSchema
public static org.apache.avro.Schema simpleSchema(tools.jackson.databind.jsonFormatVisitors.JsonFormatTypes type, tools.jackson.databind.JavaType hint) -
numericAvroSchema
public static org.apache.avro.Schema numericAvroSchema(tools.jackson.core.JsonParser.NumberType type) -
numericAvroSchema
public static org.apache.avro.Schema numericAvroSchema(tools.jackson.core.JsonParser.NumberType type, tools.jackson.databind.JavaType hint) -
typedSchema
public static org.apache.avro.Schema typedSchema(org.apache.avro.Schema.Type nativeType, tools.jackson.databind.JavaType javaType) Helper method for constructing type-tagged "native" Avro Schema instance. -
anyNumberSchema
public static org.apache.avro.Schema anyNumberSchema() -
stringableKeyMapSchema
public static org.apache.avro.Schema stringableKeyMapSchema(tools.jackson.databind.JavaType mapType, tools.jackson.databind.JavaType keyType, org.apache.avro.Schema valueSchema) -
throwUnsupported
protected static <T> T throwUnsupported() -
initializeRecordSchema
public static org.apache.avro.Schema initializeRecordSchema(tools.jackson.databind.cfg.MapperConfig<?> config, tools.jackson.databind.JavaType type, tools.jackson.databind.introspect.AnnotatedClass annotations) Initializes a record schema with metadata from the given class; this schema is returned in a non-finalized state, and still needs to have fields added to it. -
parseJsonSchema
Parses a JSON-formatted representation of a schema -
createEnumSchema
public static org.apache.avro.Schema createEnumSchema(tools.jackson.databind.cfg.MapperConfig<?> config, tools.jackson.databind.JavaType enumType, tools.jackson.databind.introspect.AnnotatedClass annotations, List<String> values) Constructs a new enum schema- Parameters:
values- List of enum names- Returns:
- An
ENUMschema.
-
createUUIDSchema
public static org.apache.avro.Schema createUUIDSchema()Helper method to enclose details of expressing best Avro Schema forUUID: 16-byte fixed-length binary (alternative would be basic variable length "bytes"). -
addAlias
public static org.apache.avro.Schema addAlias(org.apache.avro.Schema schema, tools.jackson.databind.introspect.AnnotatedClass annotations) Looks for@AvroAliasonbeanand adds it toschemaif it exists- Parameters:
schema- Schema to which the alias should be addedannotations- Set of possibly relevant annotations- Returns:
schema, possibly with an alias added
-
getTypeId
-
getTypeId
Returns the Avro type ID for a given type -
getTypeId
Returns the type ID for this schema, ornullif none is present. -
getFullName
Returns the full name of a schema; This is similar toSchema.getFullName(), except that it properly handles namespaces for nested classes. (package.name.ClassName$NestedClassNameinstead ofpackage.name.ClassName$.NestedClassName)WARNING! This method has to probe for nested classes in order to resolve whether or not a schema references a top-level class or a nested class and return the corresponding name for each.
-
nullNode
public static tools.jackson.databind.JsonNode nullNode() -
objectToJsonNode
-
jsonNodeToObject
-
parseDefaultValue
public static tools.jackson.databind.JsonNode parseDefaultValue(String defaultValue) throws tools.jackson.databind.DatabindException Converts a default value represented as a string (such as from a schema specification) into a JsonNode for further handling.- Parameters:
defaultValue- The default value to parse, in the form of a JSON string- Returns:
- a parsed JSON representation of the default value
- Throws:
tools.jackson.databind.DatabindException- IfdefaultValueis not valid JSON
-