Package org.apache.avro.reflect
Class ReflectData
java.lang.Object
org.apache.avro.generic.GenericData
org.apache.avro.specific.SpecificData
org.apache.avro.reflect.ReflectData
- Direct Known Subclasses:
ReflectData.AllowNull
Utilities to use existing Java classes and interfaces via reflection.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
ReflectData
implementation that permits null field values.Nested classes/interfaces inherited from class org.apache.avro.specific.SpecificData
SpecificData.SchemaConstructable
Nested classes/interfaces inherited from class org.apache.avro.generic.GenericData
GenericData.AbstractArray<T>, GenericData.Array<T>, GenericData.EnumSymbol, GenericData.Fixed, GenericData.InstanceSupplier, GenericData.Record, GenericData.StringType
-
Field Summary
Fields inherited from class org.apache.avro.specific.SpecificData
ACCESSOR_MUTATOR_RESERVED_WORDS, CLASS_PROP, ELEMENT_PROP, ERROR_RESERVED_WORDS, KEY_CLASS_PROP, RESERVED_WORD_ESCAPE_CHAR, RESERVED_WORDS, stringableClasses, TYPE_IDENTIFIER_RESERVED_WORDS
Fields inherited from class org.apache.avro.generic.GenericData
FAST_READER_PROP, STRING_PROP, STRING_TYPE_STRING
-
Constructor Summary
ConstructorDescriptionFor subclasses.ReflectData
(ClassLoader classLoader) Construct with a particular classloader. -
Method Summary
Modifier and TypeMethodDescriptionCause a class to be treated as though it had anStringable
* annotation.protected int
Comparison implementation.createDatumReader
(Schema schema) Returns aDatumReader
for this kind of data.createDatumReader
(Schema writer, Schema reader) Returns aDatumReader
for this kind of data.createDatumWriter
(Schema schema) Returns aDatumWriter
for this kind of data.protected Schema
createFieldSchema
(Field field, Map<String, Schema> names) Create a schema for a field.createFixed
(Object old, Schema schema) Called to create an fixed value.protected Schema
createSchema
(Type type, Map<String, Schema> names) Create the schema for a Java type.protected Object
createSchemaDefaultValue
(Type type, Field field, Schema fieldSchema) Get default value for a schema field.static ReflectData
get()
Return the singleton instance.protected Collection
getArrayAsCollection
(Object datum) Called to access an array as a collection.Return the class that implements a schema, or null if none exists.Called byGenericDatumReader.readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to retrieve a record field value from a reused instance.protected Object
Version ofGenericData.getField(java.lang.Object, java.lang.String, int)
that has state.protected Object
getOrCreateDefaultValue
(Type type) Get or create new value instance for a type.protected Object
getOrCreateDefaultValue
(Type type, Field field) Get or create new value instance for a fieldgetProtocol
(Class iface) Return the protocol for a Java interface.protected Schema
getRecordSchema
(Object record) Called to obtain the schema of a record.protected Object
getRecordState
(Object record, Schema schema) Produce state for repeated calls toGenericData.getField(Object,String,int,Object)
andGenericData.setField(Object,String,int,Object,Object)
on the same record.protected boolean
Returns true for arrays and false otherwise, with the following exceptions:protected boolean
Called by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object)
.protected boolean
It returns false for non-string-maps because Avro writes out such maps as an array of records.protected boolean
Called by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object)
.protected boolean
isStringable
(Class<?> c) True if a class should be serialized with toString().static Schema
makeNullable
(Schema schema) Create and return a union of the null schema and the provided schema.Called to create new record instances.setDefaultGeneratedValue
(Type type, Object value) Set the default value for a type.setDefaultsGenerated
(boolean enabled) Enable or disable `default reflection`void
Called byGenericDatumReader.readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to set a record fields value to a record instance.protected void
Version ofGenericData.setField(java.lang.Object, java.lang.String, int, java.lang.Object)
that has state.boolean
Always false since custom coders are not available forReflectData
.boolean
Returns true if a Java datum matches a schema.Methods inherited from class org.apache.avro.specific.SpecificData
createEnum, createString, getClassName, getDecoder, getEncoder, getEnumSchema, getForClass, getForSchema, getNewRecordSupplier, getSchema, getSchemaName, isEnum, isStringType, mangle, mangle, mangle, mangle, mangleFullyQualified, mangleMethod, mangleTypeIdentifier, mangleTypeIdentifier, newInstance, setCustomCoders, unmangle
Methods inherited from class org.apache.avro.generic.GenericData
addLogicalTypeConversion, compare, compareMaps, createFixed, deepCopy, getClassLoader, getConversionByClass, getConversionByClass, getConversionFor, getConversions, getDefaultValue, getFastReaderBuilder, getFixedSchema, getPrimitiveTypeCache, hashCode, induce, instanceOf, isBoolean, isDouble, isFastReaderEnabled, isFixed, isFloat, isInteger, isLong, isString, newArray, newMap, resolveUnion, setFastReaderEnabled, setStringType, toString, toString
-
Constructor Details
-
ReflectData
public ReflectData()For subclasses. Applications normally useget()
. -
ReflectData
Construct with a particular classloader.
-
-
Method Details
-
useCustomCoders
public boolean useCustomCoders()Always false since custom coders are not available forReflectData
.- Overrides:
useCustomCoders
in classSpecificData
-
get
Return the singleton instance. -
addStringable
Cause a class to be treated as though it had anStringable
* annotation. -
setDefaultsGenerated
Enable or disable `default reflection`- Parameters:
enabled
- set to `true` to enable the feature. This feature is disabled by default- Returns:
- The current instance
-
setDefaultGeneratedValue
Set the default value for a type. When encountering such type, we'll use this provided value instead of trying to create a new one.NOTE: This method automatically enable feature `default reflection`.
- Parameters:
type
- The typevalue
- Its default value- Returns:
- The current instance
-
getOrCreateDefaultValue
Get or create new value instance for a field- Parameters:
type
- The current typefield
- A child field- Returns:
- The default field value
-
getOrCreateDefaultValue
Get or create new value instance for a type. New instances will be instantiated using no-arg constructors. The newly created one will be cached for later use.- Parameters:
type
- The type- Returns:
- The value
-
createDatumReader
Description copied from class:GenericData
Returns aDatumReader
for this kind of data.- Overrides:
createDatumReader
in classSpecificData
-
createDatumReader
Description copied from class:GenericData
Returns aDatumReader
for this kind of data.- Overrides:
createDatumReader
in classSpecificData
-
createDatumWriter
Description copied from class:GenericData
Returns aDatumWriter
for this kind of data.- Overrides:
createDatumWriter
in classSpecificData
-
setField
Description copied from class:GenericData
Called byGenericDatumReader.readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to set a record fields value to a record instance. The default implementation is forIndexedRecord
.- Overrides:
setField
in classGenericData
-
setField
Description copied from class:GenericData
Version ofGenericData.setField(java.lang.Object, java.lang.String, int, java.lang.Object)
that has state.- Overrides:
setField
in classGenericData
-
getField
Description copied from class:GenericData
Called byGenericDatumReader.readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to retrieve a record field value from a reused instance. The default implementation is forIndexedRecord
.- Overrides:
getField
in classGenericData
-
getField
Description copied from class:GenericData
Version ofGenericData.getField(java.lang.Object, java.lang.String, int)
that has state.- Overrides:
getField
in classGenericData
-
isRecord
Description copied from class:GenericData
Called by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object)
.- Overrides:
isRecord
in classGenericData
-
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.
- Overrides:
isArray
in classGenericData
-
-
getArrayAsCollection
Description copied from class:GenericData
Called to access an array as a collection.- Overrides:
getArrayAsCollection
in classGenericData
-
isBytes
Description copied from class:GenericData
Called by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object)
.- Overrides:
isBytes
in classGenericData
-
getRecordSchema
Description copied from class:GenericData
Called to obtain the schema of a record. By default calls {GenericContainer#getSchema(). May be overridden for alternate record representations.- Overrides:
getRecordSchema
in classGenericData
-
validate
Description copied from class:GenericData
Returns true if a Java datum matches a schema.- Overrides:
validate
in classGenericData
-
isMap
It returns false for non-string-maps because Avro writes out such maps as an array of records. Even their JSON representation is an array.- Overrides:
isMap
in classGenericData
-
getClass
Description copied from class:SpecificData
Return the class that implements a schema, or null if none exists.- Overrides:
getClass
in classSpecificData
-
createSchemaDefaultValue
Get default value for a schema field. Derived classes can override this method to provide values based on object instantiation- Parameters:
type
- Typefield
- FieldfieldSchema
- Schema of the field- Returns:
- The default value
-
createSchema
Description copied from class:SpecificData
Create the schema for a Java type.- Overrides:
createSchema
in classSpecificData
-
isStringable
Description copied from class:SpecificData
True if a class should be serialized with toString().- Overrides:
isStringable
in classSpecificData
-
makeNullable
Create and return a union of the null schema and the provided schema. -
createFieldSchema
Create a schema for a field. -
getProtocol
Return the protocol for a Java interface.The correct name of the method parameters needs the
-parameters
java compiler argument. More info at https://openjdk.java.net/jeps/118- Overrides:
getProtocol
in classSpecificData
-
compare
Description copied from class:GenericData
Comparison implementation. When equals is true, only checks for equality, not for order.- Overrides:
compare
in classSpecificData
-
getRecordState
Description copied from class:GenericData
Produce state for repeated calls toGenericData.getField(Object,String,int,Object)
andGenericData.setField(Object,String,int,Object,Object)
on the same record.- Overrides:
getRecordState
in classGenericData
-
createFixed
Description copied from class:GenericData
Called to create an fixed value. May be overridden for alternate fixed representations. By default, returnsGenericFixed
.- Overrides:
createFixed
in classSpecificData
-
newRecord
Description copied from class:GenericData
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 aGenericData.Record
.- Overrides:
newRecord
in classSpecificData
-