Top Inners Fields Constructors Methods
com.fasterxml.jackson.dataformat.avro.schema

public abstract Class AvroSchemaHelper

extends Object
Class Inheritance
Imports
java.io.File, java.math.BigDecimal, .BigInteger, java.net.URI, .URL, java.util.*, org.apache.avro.JsonProperties, .Schema, .Schema.Parser, org.apache.avro.reflect.AvroAlias, .Stringable, org.apache.avro.specific.SpecificData, com.fasterxml.jackson.core.JsonParser, .JsonProcessingException, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.introspect.AnnotatedClass, .AnnotatedConstructor, com.fasterxml.jackson.databind.json.JsonMapper, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes, com.fasterxml.jackson.databind.util.ClassUtil, .LRUMap, com.fasterxml.jackson.dataformat.avro.annotation.AvroNamespace

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final 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.

public static final 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.

public static final 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.

private static final ObjectMapper
DEFAULT_VALUE_MAPPER

Dedicated mapper for handling default values (String <-> JsonNode <-> Object)

protected static final Set<Class<?>>
STRINGABLE_CLASSES

Default stringable classes

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Schema

Returns:

schema, possibly with an alias added
addAlias
(Schema
Schema to which the alias should be added
schema
,
BeanDescription
Bean to inspect for type aliases
bean
)

Looks for @AvroAlias on bean and adds it to schema if it exists

public static Schema
public static Schema

Returns:

An ENUM schema.
createEnumSchema
(BeanDescription
Enum type to use for name / description / namespace
bean
,
List<String>
List of enum names
values
)

Constructs a new enum schema

public static Schema
createUUIDSchema()

Helper method to enclose details of expressing best Avro Schema for java.util.UUID: 16-byte fixed-length binary (alternative would be basic variable length "bytes").

public static String
getFullName(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
protected static String
getName(Class<?> cls)

protected static String
protected static String
public static String
public static String
getTypeId(Class<?> type)

Returns the Avro type ID for a given type

public static String
getTypeId(Schema schema)

Returns the type ID for this schema, or null if none is present.

public static Schema
initializeRecordSchema(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.

public static boolean

Returns:

true if it can be stored in a string schema, otherwise false
isStringable
(AnnotatedClass
Type to check if it can be serialized to a Avro string schema
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.

public static Object
jsonNodeToObject(JsonNode defaultJsonValue)

public static JsonNode
public static Schema
public static Schema
public static JsonNode
objectToJsonNode(Object defaultValue)

public static JsonNode

Returns:

a parsed JSON representation of the default value
parseDefaultValue
(String
The default value to parse, in the form of a JSON string
defaultValue
)

Converts a default value represented as a string (such as from a schema specification) into a JsonNode for further handling.

public static Schema
parseJsonSchema(String json)

Parses a JSON-formatted representation of a schema

public static Schema
public static Schema
stringableKeyMapSchema(JavaType mapType, JavaType keyType, Schema valueSchema)

protected static <T> T
public static Schema
typedSchema(Schema.Type nativeType, JavaType javaType)

Helper method for constructing type-tagged "native" Avro Schema instance.

protected static Schema
unionWithNull(Schema otherSchema)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AVRO_SCHEMA_PROP_CLASSback to summary
public static final 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.

Since
2.8.7
AVRO_SCHEMA_PROP_ELEMENT_CLASSback to summary
public static final 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.

Since
2.8.8
AVRO_SCHEMA_PROP_KEY_CLASSback to summary
public static final 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.

Since
2.8.7
DEFAULT_VALUE_MAPPERback to summary
private static final ObjectMapper DEFAULT_VALUE_MAPPER

Dedicated mapper for handling default values (String <-> JsonNode <-> Object)

Since
2.11
STRINGABLE_CLASSESback to summary
protected static final Set<Class<?>> STRINGABLE_CLASSES

Default stringable classes

Since
2.8.7

Constructor Detail

AvroSchemaHelperback to summary
public AvroSchemaHelper()

Method Detail

addAliasback to summary
public static Schema addAlias(Schema schema, BeanDescription bean)

Looks for @AvroAlias on bean and adds it to schema if it exists

Parameters
schema:Schema

Schema to which the alias should be added

bean:BeanDescription

Bean to inspect for type aliases

Returns:Schema

schema, possibly with an alias added

anyNumberSchemaback to summary
public static Schema anyNumberSchema()
createEnumSchemaback to summary
public static Schema createEnumSchema(BeanDescription bean, List<String> values)

Constructs a new enum schema

Parameters
bean:BeanDescription

Enum type to use for name / description / namespace

values:List<String>

List of enum names

Returns:Schema

An ENUM schema.

createUUIDSchemaback to summary
public static Schema createUUIDSchema()

Helper method to enclose details of expressing best Avro Schema for java.util.UUID: 16-byte fixed-length binary (alternative would be basic variable length "bytes").

Since
2.11
getFullNameback to summary
public static String getFullName(Schema schema)

Returns the full name of a schema; This is similar to 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.

getNameback to summary
protected static String getName(JavaType type)
getNameback to summary
protected static String getName(Class<?> cls)
getNamespaceback to summary
protected static String getNamespace(JavaType type, AnnotatedClass annotations)
getNamespaceback to summary
protected static String getNamespace(Class<?> cls)
getTypeIdback to summary
public static String getTypeId(JavaType type)
getTypeIdback to summary
public static String getTypeId(Class<?> type)

Returns the Avro type ID for a given type

getTypeIdback to summary
public static String getTypeId(Schema schema)

Returns the type ID for this schema, or null if none is present.

initializeRecordSchemaback to summary
public static Schema initializeRecordSchema(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.

isStringableback to summary
public static boolean isStringable(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.

Parameters
type:AnnotatedClass

Type to check if it can be serialized to a Avro string schema

Returns:boolean

true if it can be stored in a string schema, otherwise false

jsonNodeToObjectback to summary
public static Object jsonNodeToObject(JsonNode defaultJsonValue)
Since
2.11
nullNodeback to summary
public static JsonNode nullNode()
numericAvroSchemaback to summary
public static Schema numericAvroSchema(JsonParser.NumberType type)
numericAvroSchemaback to summary
public static Schema numericAvroSchema(JsonParser.NumberType type, JavaType hint)
objectToJsonNodeback to summary
public static JsonNode objectToJsonNode(Object defaultValue)
Since
2.11
parseDefaultValueback to summary
public static JsonNode parseDefaultValue(String defaultValue) throws JsonMappingException

Converts a default value represented as a string (such as from a schema specification) into a JsonNode for further handling.

Parameters
defaultValue:String

The default value to parse, in the form of a JSON string

Returns:JsonNode

a parsed JSON representation of the default value

Exceptions
JsonMappingException:
If defaultValue is not valid JSON
Since
2.11
parseJsonSchemaback to summary
public static Schema parseJsonSchema(String json)

Parses a JSON-formatted representation of a schema

simpleSchemaback to summary
public static Schema simpleSchema(JsonFormatTypes type, JavaType hint)
stringableKeyMapSchemaback to summary
public static Schema stringableKeyMapSchema(JavaType mapType, JavaType keyType, Schema valueSchema)
throwUnsupportedback to summary
protected static <T> T throwUnsupported()
typedSchemaback to summary
public static Schema typedSchema(Schema.Type nativeType, JavaType javaType)

Helper method for constructing type-tagged "native" Avro Schema instance.

Since
2.8.7
unionWithNullback to summary
protected static Schema unionWithNull(Schema otherSchema)
com.fasterxml.jackson.dataformat.avro.schema back to summary

private final Class AvroSchemaHelper.FullNameKey

extends Object
Class Inheritance
  • java.lang.Object
  • com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaHelper.FullNameKey

Field Summary

Modifier and TypeField and Description
private final int
private final String
private final String

Constructor Summary

AccessConstructor and Description
public
FullNameKey(String namespace, String name)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

_hashCodeback to summary
private final int _hashCode
_nameback to summary
private final String _name
_namespaceback to summary
private final String _namespace

Constructor Detail

FullNameKeyback to summary
public FullNameKey(String namespace, String name)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
nameWithSeparatorback to summary
public String nameWithSeparator(char sep)
com.fasterxml.jackson.dataformat.avro.schema back to summary

private final Class AvroSchemaHelper.FullNameResolver

extends Object
Class Inheritance
  • java.lang.Object
  • com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaHelper.FullNameResolver

Field Summary

Modifier and TypeField and Description
public static final AvroSchemaHelper.FullNameResolver
private final LRUMap<AvroSchemaHelper.FullNameKey, String>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static String
public String
resolve(final String namespace, final String name)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

instanceback to summary
public static final AvroSchemaHelper.FullNameResolver instance
SCHEMA_NAME_CACHEback to summary
private final LRUMap<AvroSchemaHelper.FullNameKey, String> SCHEMA_NAME_CACHE

Constructor Detail

FullNameResolverback to summary
private FullNameResolver()

Method Detail

_resolveback to summary
private static String _resolve(AvroSchemaHelper.FullNameKey key)
resolveback to summary
public String resolve(final String namespace, final String name)