public abstract class AvroSchemaHelper extends Object
Modifier and Type | Field and Description |
---|---|
static String |
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.
|
static String |
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.
|
static String |
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.
|
protected static Set<Class<?>> |
STRINGABLE_CLASSES
Default stringable classes
|
Constructor and Description |
---|
AvroSchemaHelper() |
Modifier and Type | Method and Description |
---|---|
static org.apache.avro.Schema |
addAlias(org.apache.avro.Schema schema,
com.fasterxml.jackson.databind.BeanDescription bean)
Looks for
@AvroAlias on bean and adds it to schema if it exists |
static org.apache.avro.Schema |
anyNumberSchema() |
static org.apache.avro.Schema |
createEnumSchema(com.fasterxml.jackson.databind.BeanDescription bean,
List<String> values)
Constructs a new enum schema
|
static org.apache.avro.Schema |
createUUIDSchema()
Helper method to enclose details of expressing best Avro Schema for
UUID : 16-byte fixed-length binary (alternative would
be basic variable length "bytes"). |
static String |
getFullName(org.apache.avro.Schema schema)
Returns the full name of a schema; This is similar to
Schema.getFullName() , except that it properly handles namespaces for
nested classes. |
protected static String |
getName(Class<?> cls) |
protected static String |
getName(com.fasterxml.jackson.databind.JavaType type) |
protected static String |
getNamespace(Class<?> cls) |
protected static String |
getNamespace(com.fasterxml.jackson.databind.JavaType type) |
static String |
getTypeId(Class<?> type)
Returns the Avro type ID for a given type
|
static String |
getTypeId(com.fasterxml.jackson.databind.JavaType type) |
static String |
getTypeId(org.apache.avro.Schema schema)
Returns the type ID for this schema, or
null if none is present. |
static org.apache.avro.Schema |
initializeRecordSchema(com.fasterxml.jackson.databind.BeanDescription bean)
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 boolean |
isStringable(com.fasterxml.jackson.databind.introspect.AnnotatedClass type)
Checks if a given type is "Stringable", that is one of the default
STRINGABLE_CLASSES , is an Enum ,
or is annotated with
@Stringable and has a constructor that takes a single string argument capable of deserializing the output of its
toString() method. |
static Object |
jsonNodeToObject(com.fasterxml.jackson.databind.JsonNode defaultJsonValue) |
static org.apache.avro.Schema |
numericAvroSchema(com.fasterxml.jackson.core.JsonParser.NumberType type) |
static org.apache.avro.Schema |
numericAvroSchema(com.fasterxml.jackson.core.JsonParser.NumberType type,
com.fasterxml.jackson.databind.JavaType hint) |
static com.fasterxml.jackson.databind.JsonNode |
objectToJsonNode(Object defaultValue) |
static com.fasterxml.jackson.databind.JsonNode |
parseDefaultValue(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.Schema |
parseJsonSchema(String json)
Parses a JSON-formatted representation of a schema
|
static org.apache.avro.Schema |
simpleSchema(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes type,
com.fasterxml.jackson.databind.JavaType hint) |
static org.apache.avro.Schema |
stringableKeyMapSchema(com.fasterxml.jackson.databind.JavaType mapType,
com.fasterxml.jackson.databind.JavaType keyType,
org.apache.avro.Schema valueSchema) |
protected static <T> T |
throwUnsupported() |
static org.apache.avro.Schema |
typedSchema(org.apache.avro.Schema.Type nativeType,
com.fasterxml.jackson.databind.JavaType javaType)
Helper method for constructing type-tagged "native" Avro Schema instance.
|
protected static org.apache.avro.Schema |
unionWithNull(org.apache.avro.Schema otherSchema) |
public static final String AVRO_SCHEMA_PROP_CLASS
public static final String AVRO_SCHEMA_PROP_KEY_CLASS
public static final String AVRO_SCHEMA_PROP_ELEMENT_CLASS
public static boolean isStringable(com.fasterxml.jackson.databind.introspect.AnnotatedClass type)
STRINGABLE_CLASSES
, is an Enum
,
or is annotated with
@Stringable
and has a constructor that takes a single string argument capable of deserializing the output of its
toString()
method.type
- Type to check if it can be serialized to a Avro string schematrue
if it can be stored in a string schema, otherwise false
protected static String getNamespace(com.fasterxml.jackson.databind.JavaType type)
protected static String getName(com.fasterxml.jackson.databind.JavaType type)
protected static org.apache.avro.Schema unionWithNull(org.apache.avro.Schema otherSchema)
public static org.apache.avro.Schema simpleSchema(com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes type, com.fasterxml.jackson.databind.JavaType hint)
public static org.apache.avro.Schema numericAvroSchema(com.fasterxml.jackson.core.JsonParser.NumberType type)
public static org.apache.avro.Schema numericAvroSchema(com.fasterxml.jackson.core.JsonParser.NumberType type, com.fasterxml.jackson.databind.JavaType hint)
public static org.apache.avro.Schema typedSchema(org.apache.avro.Schema.Type nativeType, com.fasterxml.jackson.databind.JavaType javaType)
public static org.apache.avro.Schema anyNumberSchema()
public static org.apache.avro.Schema stringableKeyMapSchema(com.fasterxml.jackson.databind.JavaType mapType, com.fasterxml.jackson.databind.JavaType keyType, org.apache.avro.Schema valueSchema)
protected static <T> T throwUnsupported()
public static org.apache.avro.Schema initializeRecordSchema(com.fasterxml.jackson.databind.BeanDescription bean)
public static org.apache.avro.Schema parseJsonSchema(String json)
public static org.apache.avro.Schema createEnumSchema(com.fasterxml.jackson.databind.BeanDescription bean, List<String> values)
bean
- Enum type to use for name / description / namespacevalues
- List of enum namesENUM
schema.public static org.apache.avro.Schema createUUIDSchema()
UUID
: 16-byte fixed-length binary (alternative would
be basic variable length "bytes").public static org.apache.avro.Schema addAlias(org.apache.avro.Schema schema, com.fasterxml.jackson.databind.BeanDescription bean)
@AvroAlias
on bean
and adds it to schema
if it existsschema
- Schema to which the alias should be addedbean
- Bean to inspect for type aliasesschema
, possibly with an alias addedpublic static String getTypeId(com.fasterxml.jackson.databind.JavaType type)
public static String getTypeId(org.apache.avro.Schema schema)
null
if none is present.public static String getFullName(org.apache.avro.Schema schema)
Schema.getFullName()
, except that it properly handles namespaces for
nested classes. (package.name.ClassName$NestedClassName
instead of package.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.
public static com.fasterxml.jackson.databind.JsonNode objectToJsonNode(Object defaultValue)
public static Object jsonNodeToObject(com.fasterxml.jackson.databind.JsonNode defaultJsonValue)
public static com.fasterxml.jackson.databind.JsonNode parseDefaultValue(String defaultValue) throws com.fasterxml.jackson.databind.JsonMappingException
defaultValue
- The default value to parse, in the form of a JSON stringcom.fasterxml.jackson.databind.JsonMappingException
- If defaultValue
is not valid JSONCopyright © 2020 FasterXML. All rights reserved.