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
Nested ClassesModifier and TypeClassDescriptionstatic classReflectDataimplementation that permits null field values.Nested classes/interfaces inherited from class org.apache.avro.specific.SpecificData
SpecificData.SchemaConstructableNested 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_WORDSFields inherited from class org.apache.avro.generic.GenericData
FAST_READER_PROP, STRING_PROP, STRING_TYPE_STRING -
Constructor Summary
ConstructorsConstructorDescriptionFor 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 intComparison implementation.createDatumReader(Schema schema) Returns aDatumReaderfor this kind of data.createDatumReader(Schema writer, Schema reader) Returns aDatumReaderfor this kind of data.createDatumWriter(Schema schema) Returns aDatumWriterfor this kind of data.protected SchemacreateFieldSchema(Field field, Map<String, Schema> names) Create a schema for a field.createFixed(Object old, Schema schema) Called to create an fixed value.protected SchemacreateSchema(Type type, Map<String, Schema> names) Create the schema for a Java type.protected ObjectcreateSchemaDefaultValue(Type type, Field field, Schema fieldSchema) Get default value for a schema field.static ReflectDataget()Return the singleton instance.protected CollectiongetArrayAsCollection(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 ObjectVersion ofGenericData.getField(java.lang.Object, java.lang.String, int)that has state.protected ObjectgetOrCreateDefaultValue(Type type) Get or create new value instance for a type.protected ObjectgetOrCreateDefaultValue(Type type, Field field) Get or create new value instance for a fieldgetProtocol(Class iface) Return the protocol for a Java interface.protected SchemagetRecordSchema(Object record) Called to obtain the schema of a record.protected ObjectgetRecordState(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 booleanReturns true for arrays and false otherwise, with the following exceptions:protected booleanCalled by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).protected booleanIt returns false for non-string-maps because Avro writes out such maps as an array of records.protected booleanCalled by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).protected booleanisStringable(Class<?> c) True if a class should be serialized with toString().static SchemamakeNullable(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`voidCalled 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 voidVersion ofGenericData.setField(java.lang.Object, java.lang.String, int, java.lang.Object)that has state.booleanAlways false since custom coders are not available forReflectData.booleanReturns 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, unmangleMethods 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:
useCustomCodersin 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:GenericDataReturns aDatumReaderfor this kind of data.- Overrides:
createDatumReaderin classSpecificData
-
createDatumReader
Description copied from class:GenericDataReturns aDatumReaderfor this kind of data.- Overrides:
createDatumReaderin classSpecificData
-
createDatumWriter
Description copied from class:GenericDataReturns aDatumWriterfor this kind of data.- Overrides:
createDatumWriterin classSpecificData
-
setField
Description copied from class:GenericDataCalled 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:
setFieldin classGenericData
-
setField
Description copied from class:GenericDataVersion ofGenericData.setField(java.lang.Object, java.lang.String, int, java.lang.Object)that has state.- Overrides:
setFieldin classGenericData
-
getField
Description copied from class:GenericDataCalled 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:
getFieldin classGenericData
-
getField
Description copied from class:GenericDataVersion ofGenericData.getField(java.lang.Object, java.lang.String, int)that has state.- Overrides:
getFieldin classGenericData
-
isRecord
Description copied from class:GenericDataCalled by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).- Overrides:
isRecordin 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:
isArrayin classGenericData
-
-
getArrayAsCollection
Description copied from class:GenericDataCalled to access an array as a collection.- Overrides:
getArrayAsCollectionin classGenericData
-
isBytes
Description copied from class:GenericDataCalled by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).- Overrides:
isBytesin classGenericData
-
getRecordSchema
Description copied from class:GenericDataCalled to obtain the schema of a record. By default calls {GenericContainer#getSchema(). May be overridden for alternate record representations.- Overrides:
getRecordSchemain classGenericData
-
validate
Description copied from class:GenericDataReturns true if a Java datum matches a schema.- Overrides:
validatein 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:
isMapin classGenericData
-
getClass
Description copied from class:SpecificDataReturn the class that implements a schema, or null if none exists.- Overrides:
getClassin 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:SpecificDataCreate the schema for a Java type.- Overrides:
createSchemain classSpecificData
-
isStringable
Description copied from class:SpecificDataTrue if a class should be serialized with toString().- Overrides:
isStringablein 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
-parametersjava compiler argument. More info at https://openjdk.java.net/jeps/118- Overrides:
getProtocolin classSpecificData
-
compare
Description copied from class:GenericDataComparison implementation. When equals is true, only checks for equality, not for order.- Overrides:
comparein classSpecificData
-
getRecordState
Description copied from class:GenericDataProduce state for repeated calls toGenericData.getField(Object,String,int,Object)andGenericData.setField(Object,String,int,Object,Object)on the same record.- Overrides:
getRecordStatein classGenericData
-
createFixed
Description copied from class:GenericDataCalled to create an fixed value. May be overridden for alternate fixed representations. By default, returnsGenericFixed.- Overrides:
createFixedin classSpecificData
-
newRecord
Description copied from class:GenericDataCalled 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:
newRecordin classSpecificData
-