Top Description Inners Fields Constructors Methods
org.apache.avro.specific

public Class SpecificData

extends GenericData
Class Inheritance
Known Direct Subclasses
org.apache.avro.reflect.ReflectData
Imports
org.apache.avro.AvroRuntimeException, .AvroTypeException, .Protocol, .Schema, .Schema.Type, org.apache.avro.generic.GenericData, org.apache.avro.io.BinaryDecoder, .BinaryEncoder, .DatumReader, .DatumWriter, .DecoderFactory, .EncoderFactory, org.apache.avro.util.ClassUtils, .MapUtil, .SchemaUtil, org.apache.avro.util.internal.ClassValueCache, java.io.ObjectInput, .ObjectOutput, java.lang.reflect.Constructor, .Field, .ParameterizedType, java.nio.ByteBuffer, java.util.Arrays, .Collection, .Collections, .HashMap, .HashSet, .List, .Map, .Set, .WeakHashMap, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.function.Function

Utilities for generated Java classes and interfaces.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
SpecificData.SchemaConstructable

Tag interface that indicates that a class has a one-argument constructor that accepts a Schema.

Field Summary

Modifier and TypeField and Description
public static final String
private final ConcurrentMap<String, Class<T>>
private static final Function<Class<?>, Constructor<?>>
public static final String
private static final SpecificData
public static final String
private static final Function<Class<?>, SpecificData>
private static final Class<?>[]
private static final Class<T>
private static final Schema
public static final char
public static final Set<String>
RESERVED_WORDS

Reserved words from https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html require mangling in order to be used in generated Java code.

private static final Class<?>[]
private final ClassValueCache<Schema>
private final Map<Type, Schema>
protected Set<Class<T>>
stringableClasses

Read/write some common builtin classes as strings.

private boolean
Inherited from org.apache.avro.generic.GenericData:
FAST_READER_PROPSTRING_PROPSTRING_TYPE_STRING

Constructor Summary

AccessConstructor and Description
public
SpecificData()

For subclasses.

public
SpecificData(ClassLoader classLoader)

Construct with a specific classloader.

Method Summary

Modifier and TypeMethod and Description
protected int
compare(Object o1, Object o2, Schema s, boolean eq)

Overrides org.apache.avro.generic.GenericData.compare.

Comparison implementation.
public DatumReader<D>
public DatumReader<D>
createDatumReader(Schema writer, Schema reader)

Overrides org.apache.avro.generic.GenericData.createDatumReader.

Returns a DatumReader for this kind of data.
public DatumWriter<D>
public Object
createEnum(String symbol, Schema schema)

Overrides org.apache.avro.generic.GenericData.createEnum.

Called to create an enum value.
public Object
createFixed(Object old, Schema schema)

Overrides org.apache.avro.generic.GenericData.createFixed.

Called to create an fixed value.
protected Schema
createSchema(Type type, Map<String, Schema> names)

Create the schema for a Java type.

public Object
createString(Object value)

Overrides org.apache.avro.generic.GenericData.createString.

Called to create an string value.
public static SpecificData
get()

Hides org.apache.avro.generic.GenericData.get.

Return the singleton instance.
public Class<T>
getClass(Schema schema)

Return the class that implements a schema, or null if none exists.

public static String
getClassName(Schema schema)

Returns the Java class name indicated by a schema's name and namespace.

public static BinaryDecoder
getDecoder(ObjectInput in)

Runtime utility used by generated classes.

public static BinaryEncoder
getEncoder(ObjectOutput out)

Runtime utility used by generated classes.

protected Schema
getEnumSchema(Object datum)

Overrides org.apache.avro.generic.GenericData.getEnumSchema.

Called to obtain the schema of a enum.
public static <
.
T
>
SpecificData

Returns:

The SpecificData from the SpecificRecordBase instance, or the default SpecificData instance.
getForClass
(Class<T>
A class
c
)

If the given class is assignable to SpecificRecordBase, this method returns the SpecificData instance from the field MODEL$, in order to get the correct org.apache.avro.Conversion instances for the class.

public static SpecificData

Returns:

the SpecificData associated with the schema's class, or the default instance.
getForSchema
(Schema
the reader schema
reader
)

For RECORD and UNION type schemas, this method returns the SpecificData instance of the class associated with the schema, in order to get the right conversions for any logical types used.

public GenericData.InstanceSupplier
getNewRecordSupplier(Schema schema)

Overrides org.apache.avro.generic.GenericData.getNewRecordSupplier.

create a supplier that allows to get new record instances for a given schema in an optimized way
public Protocol
getProtocol(Class<T> iface)

Return the protocol for a Java interface.

public Schema
getSchema(Type type)

Find the schema for a Java type.

protected String
getSchemaName(Object datum)

Overrides org.apache.avro.generic.GenericData.getSchemaName.

Return the schema full name for a datum.
private Class<T>
protected boolean
isEnum(Object datum)

Overrides org.apache.avro.generic.GenericData.isEnum.

Called by the default implementation of instanceOf.
protected boolean
isStringable(Class<?> c)

True if a class should be serialized with toString().

protected boolean
isStringType(Class<?> c)

True if a class IS a string type

public static Object
newInstance(Class<T> c, Schema s)

Create an instance of a class.

public Object
newRecord(Object old, Schema schema)

Overrides org.apache.avro.generic.GenericData.newRecord.

Called to create new record instances.
public void
setCustomCoders(boolean flag)

Dynamically set the value of the custom-coder feature flag.

protected static String
unmangle(String word)

Undoes mangling for reserved words.

public boolean
useCustomCoders()

Retrieve the current value of the custom-coders feature flag.

Inherited from org.apache.avro.generic.GenericData:
addLogicalTypeConversioncomparecompareMapscreateFixeddeepCopygetArrayAsCollectiongetClassLoadergetConversionByClassgetConversionByClassgetConversionForgetConversionsgetDefaultValuegetFastReaderBuildergetFieldgetFieldgetFixedSchemagetPrimitiveTypeCachegetRecordSchemagetRecordStatehashCodehashCodeAddinduceinstanceOfisArrayisBooleanisBytesisDoubleisFastReaderEnabledisFixedisFloatisIntegerisLongisMapisRecordisStringnewArraynewMapresolveUnionsetFastReaderEnabledsetFieldsetFieldsetStringTypetoStringtoStringvalidate

Field Detail

CLASS_PROPback to summary
public static final String CLASS_PROP
classCacheback to summary
private final ConcurrentMap<String, Class<T>> classCache
CTOR_CACHEback to summary
private static final Function<Class<?>, Constructor<?>> CTOR_CACHE
ELEMENT_PROPback to summary
public static final String ELEMENT_PROP
INSTANCEback to summary
private static final SpecificData INSTANCE

Hides org.apache.avro.generic.GenericData.INSTANCE.

KEY_CLASS_PROPback to summary
public static final String KEY_CLASS_PROP
MODEL_CACHEback to summary
private static final Function<Class<?>, SpecificData> MODEL_CACHE
NO_ARGback to summary
private static final Class<?>[] NO_ARG
NO_CLASSback to summary
private static final Class<T> NO_CLASS
NULL_SCHEMAback to summary
private static final Schema NULL_SCHEMA
RESERVED_WORD_ESCAPE_CHARback to summary
public static final char RESERVED_WORD_ESCAPE_CHAR
RESERVED_WORDSback to summary
public static final Set<String> RESERVED_WORDS

Reserved words from https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html require mangling in order to be used in generated Java code.

SCHEMA_ARGback to summary
private static final Class<?>[] SCHEMA_ARG
schemaClassCacheback to summary
private final ClassValueCache<Schema> schemaClassCache
schemaTypeCacheback to summary
private final Map<Type, Schema> schemaTypeCache
stringableClassesback to summary
protected Set<Class<T>> stringableClasses

Read/write some common builtin classes as strings. Representing these as strings isn't always best, as they aren't always ordered ideally, but at least they're stored. Also note that, for compatibility, only classes that wouldn't be otherwise correctly readable or writable should be added here, e.g., those without a no-arg constructor or those whose fields are all transient.

useCustomCoderFlagback to summary
private boolean useCustomCoderFlag

Constructor Detail

SpecificDataback to summary
public SpecificData()

For subclasses. Applications normally use SpecificData#get().

SpecificDataback to summary
public SpecificData(ClassLoader classLoader)

Construct with a specific classloader.

Method Detail

compareback to summary
protected int compare(Object o1, Object o2, Schema s, boolean eq)

Overrides org.apache.avro.generic.GenericData.compare.

Doc from org.apache.avro.generic.GenericData.compare.

Comparison implementation. When equals is true, only checks for equality, not for order.

Annotations
@Override
createDatumReaderback to summary
public DatumReader<D> createDatumReader(Schema schema)

Overrides org.apache.avro.generic.GenericData.createDatumReader.

Doc from org.apache.avro.generic.GenericData.createDatumReader.

Returns a DatumReader for this kind of data.

Annotations
@Override
createDatumReaderback to summary
public DatumReader<D> createDatumReader(Schema writer, Schema reader)

Overrides org.apache.avro.generic.GenericData.createDatumReader.

Doc from org.apache.avro.generic.GenericData.createDatumReader.

Returns a DatumReader for this kind of data.

Annotations
@Override
createDatumWriterback to summary
public DatumWriter<D> createDatumWriter(Schema schema)

Overrides org.apache.avro.generic.GenericData.createDatumWriter.

Doc from org.apache.avro.generic.GenericData.createDatumWriter.

Returns a DatumWriter for this kind of data.

Annotations
@Override
createEnumback to summary
public Object createEnum(String symbol, Schema schema)

Overrides org.apache.avro.generic.GenericData.createEnum.

Doc from org.apache.avro.generic.GenericData.createEnum.

Called to create an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.

Annotations
@Override
createFixedback to summary
public Object createFixed(Object old, Schema schema)

Overrides org.apache.avro.generic.GenericData.createFixed.

Doc from org.apache.avro.generic.GenericData.createFixed.

Called to create an fixed value. May be overridden for alternate fixed representations. By default, returns GenericFixed.

Annotations
@Override
createSchemaback to summary
protected Schema createSchema(Type type, Map<String, Schema> names)

Create the schema for a Java type.

Annotations
@SuppressWarnings:unchecked
createStringback to summary
public Object createString(Object value)

Overrides org.apache.avro.generic.GenericData.createString.

Doc from org.apache.avro.generic.GenericData.createString.

Called to create an string value. May be overridden for alternate string representations.

Annotations
@Override
getback to summary
public static SpecificData get()

Hides org.apache.avro.generic.GenericData.get.

Return the singleton instance.

getClassback to summary
public Class<T> getClass(Schema schema)

Return the class that implements a schema, or null if none exists.

getClassNameback to summary
public static String getClassName(Schema schema)

Returns the Java class name indicated by a schema's name and namespace.

getDecoderback to summary
public static BinaryDecoder getDecoder(ObjectInput in)

Runtime utility used by generated classes.

getEncoderback to summary
public static BinaryEncoder getEncoder(ObjectOutput out)

Runtime utility used by generated classes.

getEnumSchemaback to summary
protected Schema getEnumSchema(Object datum)

Overrides org.apache.avro.generic.GenericData.getEnumSchema.

Doc from org.apache.avro.generic.GenericData.getEnumSchema.

Called to obtain the schema of a enum. By default calls {GenericContainer#getSchema(). May be overridden for alternate enum representations.

Annotations
@Override
getForClassback to summary
public static <T> SpecificData getForClass(Class<T> c)

If the given class is assignable to SpecificRecordBase, this method returns the SpecificData instance from the field MODEL$, in order to get the correct org.apache.avro.Conversion instances for the class. Falls back to the default instance SpecificData#get() for other classes or if the field is not found.

Parameters
<T>
.
c:Class<T>

A class

Returns:SpecificData

The SpecificData from the SpecificRecordBase instance, or the default SpecificData instance.

getForSchemaback to summary
public static SpecificData getForSchema(Schema reader)

For RECORD and UNION type schemas, this method returns the SpecificData instance of the class associated with the schema, in order to get the right conversions for any logical types used.

Parameters
reader:Schema

the reader schema

Returns:SpecificData

the SpecificData associated with the schema's class, or the default instance.

getNewRecordSupplierback to summary
public GenericData.InstanceSupplier getNewRecordSupplier(Schema schema)

Overrides org.apache.avro.generic.GenericData.getNewRecordSupplier.

Doc from org.apache.avro.generic.GenericData.getNewRecordSupplier.

create a supplier that allows to get new record instances for a given schema in an optimized way

Annotations
@SuppressWarnings:rawtypes
@Override
getProtocolback to summary
public Protocol getProtocol(Class<T> iface)

Return the protocol for a Java interface.

getSchemaback to summary
public Schema getSchema(Type type)

Find the schema for a Java type.

getSchemaNameback to summary
protected String getSchemaName(Object datum)

Overrides org.apache.avro.generic.GenericData.getSchemaName.

Doc from org.apache.avro.generic.GenericData.getSchemaName.

Return the schema full name for a datum. Called by resolveUnion(Schema, Object).

Annotations
@Override
getWrapperback to summary
private Class<T> getWrapper(Schema schema)
isEnumback to summary
protected boolean isEnum(Object datum)

Overrides org.apache.avro.generic.GenericData.isEnum.

Doc from org.apache.avro.generic.GenericData.isEnum.

Called by the default implementation of instanceOf.

Annotations
@Override
isStringableback to summary
protected boolean isStringable(Class<?> c)

True if a class should be serialized with toString().

isStringTypeback to summary
protected boolean isStringType(Class<?> c)

True if a class IS a string type

newInstanceback to summary
public static Object newInstance(Class<T> c, Schema s)

Create an instance of a class. If the class implements SchemaConstructable, call a constructor with a org.apache.avro.Schema parameter, otherwise use a no-arg constructor.

Annotations
@SuppressWarnings:unchecked
newRecordback to summary
public Object newRecord(Object old, Schema schema)

Overrides org.apache.avro.generic.GenericData.newRecord.

Doc from org.apache.avro.generic.GenericData.newRecord.

Called to create new record instances. Subclasses may override to use a different record implementation. The returned instance must conform to the schema provided. If the old object contains fields not present in the schema, they should either be removed from the old object, or it should create a new instance that conforms to the schema. By default, this returns a GenericData.Record.

Annotations
@Override
setCustomCodersback to summary
public void setCustomCoders(boolean flag)

Dynamically set the value of the custom-coder feature flag. See SpecificData#useCustomCoders().

unmangleback to summary
protected static String unmangle(String word)

Undoes mangling for reserved words.

useCustomCodersback to summary
public boolean useCustomCoders()

Retrieve the current value of the custom-coders feature flag. Defaults to false, but this default can be overridden using the system property org.apache.avro.specific.use_custom_coders, and can be set dynamically by SpecificData#useCustomCoders(). See for more about this feature flag.

org.apache.avro.specific back to summary

public Interface SpecificData.SchemaConstructable


Tag interface that indicates that a class has a one-argument constructor that accepts a Schema.
See Also
newInstance