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

public Class ReflectData

extends SpecificData
Class Inheritance
Known Direct Subclasses
org.apache.avro.reflect.ReflectData.AllowNull
Imports
org.apache.avro.AvroRuntimeException, .AvroTypeException, .Conversion, .JsonProperties, .LogicalType, .Protocol, .Protocol.Message, .Schema, .SchemaNormalization, org.apache.avro.generic.GenericContainer, .GenericData, .GenericFixed, .IndexedRecord, org.apache.avro.io.BinaryData, .DatumReader, .DatumWriter, org.apache.avro.specific.FixedSize, .SpecificData, org.apache.avro.util.ClassUtils, .MapUtil, java.io.IOException, java.lang.annotation.Annotation, java.lang.reflect.Constructor, .Field, .GenericArrayType, .InvocationTargetException, .Method, .Modifier, .Parameter, .ParameterizedType, .Type, .TypeVariable, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.ArrayList, .Arrays, .Collection, .Collections, .Comparator, .HashMap, .IdentityHashMap, .LinkedHashMap, .List, .Map, .WeakHashMap, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap

Utilities to use existing Java classes and interfaces via reflection.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ReflectData.AllowNull

ReflectData implementation that permits null field values.

pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final ClassValue<ReflectData.ClassAccessorData>
private static final IdentityHashMap<Class<T>, Class<T>>
private static final Class<T>
private static final Map<String, Class<T>>
pack-priv static final String
private boolean
defaultGenerated

If this flag is set to true, default values for fields will be assigned dynamically using Java reflections.

private final Map<Type, Object>
pack-priv static final String
private static final ConcurrentMap<Class<?>, Field[]>
private static final ReflectData
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final int
pack-priv static final String
pack-priv static final int
private static final String
private static final Schema
Inherited from org.apache.avro.specific.SpecificData:
RESERVED_WORD_ESCAPE_CHARRESERVED_WORDSstringableClasses

Constructor Summary

AccessConstructor and Description
public
ReflectData()

For subclasses.

public
ReflectData(ClassLoader classLoader)

Construct with a particular classloader.

Method Summary

Modifier and TypeMethod and Description
public ReflectData
addStringable(Class<T> c)

Cause a class to be treated as though it had an Stringable * annotation.

protected int
compare(Object o1, Object o2, Schema s, boolean equals)

Overrides org.apache.avro.specific.SpecificData.compare.

Comparison implementation.
private void
private void
consumeFieldAlias(Field field, Schema.Field recordField)

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

Overrides org.apache.avro.specific.SpecificData.createDatumReader.

Returns a DatumReader for this kind of data.
public DatumWriter<D>
protected Schema
createFieldSchema(Field field, Map<String, Schema> names)

Create a schema for a field.

public Object
createFixed(Object old, Schema schema)

Overrides org.apache.avro.specific.SpecificData.createFixed.

Called to create an fixed value.
pack-priv Schema
createNonStringMapSchema(Type keyType, Type valueType, Map<String, Schema> names)

protected Schema
createSchema(Type type, Map<String, Schema> names)

Overrides org.apache.avro.specific.SpecificData.createSchema.

Create the schema for a Java type.
protected Object

Returns:

The default value
createSchemaDefaultValue
(Type
Type
type
,
Field
Field
field
,
Schema
Schema of the field
fieldSchema
)

Get default value for a schema field.

public static ReflectData
get()

Hides org.apache.avro.specific.SpecificData.get.

Return the singleton instance.
private FieldAccessor
getAccessorForField(Object record, String name, int pos, Object optionalState)

private Schema
protected Collection<E>
getArrayAsCollection(Object datum)

Overrides org.apache.avro.generic.GenericData.getArrayAsCollection.

Called to access an array as a collection.
private static Field[]
getCachedFields(Class<?> recordClass)

public Class<T>
getClass(Schema schema)

Overrides org.apache.avro.specific.SpecificData.getClass.

Return the class that implements a schema, or null if none exists.
private ReflectData.ClassAccessorData
pack-priv static Class<T>
getClassProp(Schema schema, String prop)

public Object
getField(Object record, String name, int position)

Overrides org.apache.avro.generic.GenericData.getField.

Called by GenericDatumReader#readRecord to retrieve a record field value from a reused instance.
protected Object
getField(Object record, String name, int pos, Object state)

Overrides org.apache.avro.generic.GenericData.getField.

Version of getField that has state.
private FieldAccessor
getFieldAccessor(Class<?> c, String fieldName)

private FieldAccessor[]
private static Field[]
getFields(Class<?> recordClass, boolean excludeJava)

private Protocol.Message
getMessage(Method method, Protocol protocol, Map<String, Schema> names, Map<? extends Type, Type> genericTypeMap)

private String
getNameForNonStringMapRecord(Type keyType, Type valueType, Schema keySchema, Schema valueSchema)

protected Object

Returns:

The default field value
getOrCreateDefaultValue
(Type
The current type
type
,
Field
A child field
field
)

Get or create new value instance for a field

protected Object

Returns:

The value
getOrCreateDefaultValue
(Type
The type
type
)

Get or create new value instance for a type.

public Protocol
getProtocol(Class<T> iface)

Overrides org.apache.avro.specific.SpecificData.getProtocol.

Return the protocol for a Java interface.
protected Schema
getRecordSchema(Object record)

Overrides org.apache.avro.generic.GenericData.getRecordSchema.

Called to obtain the schema of a record.
protected Object
private Schema
getSchema(Type type, Map<String, Schema> names)

protected boolean
isArray(Object datum)

Overrides org.apache.avro.generic.GenericData.isArray.

Returns true for arrays and false otherwise, with the following exceptions:
  • Returns true for non-string-keyed maps, which are written as an array of key/value pair records.

  • Returns false for arrays of bytes, since those should be treated as byte data type instead.

protected boolean
isBytes(Object datum)

Overrides org.apache.avro.generic.GenericData.isBytes.

Called by the default implementation of instanceOf.
protected boolean
isMap(Object datum)

Overrides org.apache.avro.generic.GenericData.isMap.

It returns false for non-string-maps because Avro writes out such maps as an array of records.
private boolean
pack-priv static boolean
protected boolean
isRecord(Object datum)

Overrides org.apache.avro.generic.GenericData.isRecord.

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

Overrides org.apache.avro.specific.SpecificData.isStringable.

True if a class should be serialized with toString().
public static Schema
makeNullable(Schema schema)

Create and return a union of the null schema and the provided schema.

public Object
newRecord(Object old, Schema schema)

Overrides org.apache.avro.specific.SpecificData.newRecord.

Called to create new record instances.
public ReflectData

Returns:

The current instance
setDefaultGeneratedValue
(Type
The type
type
,
Object
Its default value
value
)

Set the default value for a type.

public ReflectData

Returns:

The current instance
setDefaultsGenerated
(boolean
set to `true` to enable the feature. This feature is disabled by default
enabled
)

Enable or disable `default reflection`

private void
setElement(Schema schema, Type element)

public void
setField(Object record, String name, int position, Object value)

Overrides org.apache.avro.generic.GenericData.setField.

Called by GenericDatumReader#readRecord to set a record fields value to a record instance.
protected void
setField(Object record, String name, int position, Object value, Object state)

Overrides org.apache.avro.generic.GenericData.setField.

Version of setField that has state.
private String
public boolean
useCustomCoders()

Overrides org.apache.avro.specific.SpecificData.useCustomCoders.

Always false since custom coders are not available for ReflectData.
public boolean
validate(Schema schema, Object datum)

Overrides org.apache.avro.generic.GenericData.validate.

Returns true if a Java datum matches a schema.
Inherited from org.apache.avro.specific.SpecificData:
createEnumcreateStringgetClassNamegetDecodergetEncodergetEnumSchemagetForClassgetForSchemagetNewRecordSuppliergetSchemagetSchemaNameisEnumisStringTypenewInstancesetCustomCodersunmangle