Package org.apache.avro.specific
Class SpecificData
java.lang.Object
org.apache.avro.generic.GenericData
org.apache.avro.specific.SpecificData
- Direct Known Subclasses:
ReflectData
Utilities for generated Java classes and interfaces.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceTag interface that indicates that a class has a one-argument constructor that accepts a Schema.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
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final charReserved 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.Read/write some common builtin classes as strings.Fields inherited from class org.apache.avro.generic.GenericData
FAST_READER_PROP, STRING_PROP, STRING_TYPE_STRING -
Constructor Summary
ConstructorsConstructorDescriptionFor subclasses.SpecificData(ClassLoader classLoader) Construct with a specific classloader. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.createEnum(String symbol, Schema schema) Called to create an enum value.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.createString(Object value) Called to create an string value.static SpecificDataget()Return the singleton instance.Return the class that implements a schema, or null if none exists.static StringgetClassName(Schema schema) Returns the Java class name indicated by a schema's name and namespace.static BinaryDecoderRuntime utility used by generated classes.static BinaryEncodergetEncoder(ObjectOutput out) Runtime utility used by generated classes.protected SchemagetEnumSchema(Object datum) Called to obtain the schema of a enum.static <T> SpecificDatagetForClass(Class<T> c) If the given class is assignable toSpecificRecordBase, this method returns the SpecificData instance from the fieldMODEL$, in order to get the correctConversioninstances for the class.static SpecificDatagetForSchema(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.getNewRecordSupplier(Schema schema) create a supplier that allows to get new record instances for a given schema in an optimized waygetProtocol(Class iface) Return the protocol for a Java interface.Find the schema for a Java type.protected StringgetSchemaName(Object datum) Return the schema full name for a datum.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().protected booleanisStringType(Class<?> c) True if a class IS a string typestatic StringUtility for template use.static StringUtility for template use.static StringUtility for template use.static StringUtility for template use.static StringmangleFullyQualified(String fullName) Utility to mangle the fully qualified class name into a valid symbol.static StringmangleMethod(String word, boolean isError) static StringmangleTypeIdentifier(String word) Utility for template use.static StringmangleTypeIdentifier(String word, boolean isError) Utility for template use.static ObjectnewInstance(Class c, Schema s) Create an instance of a class.Called to create new record instances.voidsetCustomCoders(boolean flag) Dynamically set the value of the custom-coder feature flag.protected static StringUndoes mangling for reserved words.booleanRetrieve the current value of the custom-coders feature flag.Methods inherited from class org.apache.avro.generic.GenericData
addLogicalTypeConversion, compare, compareMaps, createFixed, deepCopy, getArrayAsCollection, getClassLoader, getConversionByClass, getConversionByClass, getConversionFor, getConversions, getDefaultValue, getFastReaderBuilder, getField, getField, getFixedSchema, getPrimitiveTypeCache, getRecordSchema, getRecordState, hashCode, induce, instanceOf, isArray, isBoolean, isBytes, isDouble, isFastReaderEnabled, isFixed, isFloat, isInteger, isLong, isMap, isRecord, isString, newArray, newMap, resolveUnion, setFastReaderEnabled, setField, setField, setStringType, toString, toString, validate
-
Field Details
-
CLASS_PROP
- See Also:
-
KEY_CLASS_PROP
- See Also:
-
ELEMENT_PROP
- See Also:
-
RESERVED_WORD_ESCAPE_CHAR
public static final char RESERVED_WORD_ESCAPE_CHAR- See Also:
-
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. -
ACCESSOR_MUTATOR_RESERVED_WORDS
-
TYPE_IDENTIFIER_RESERVED_WORDS
-
ERROR_RESERVED_WORDS
-
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.
-
-
Constructor Details
-
SpecificData
public SpecificData()For subclasses. Applications normally useget(). -
SpecificData
Construct with a specific classloader.
-
-
Method Details
-
createDatumReader
Description copied from class:GenericDataReturns aDatumReaderfor this kind of data.- Overrides:
createDatumReaderin classGenericData
-
createDatumReader
Description copied from class:GenericDataReturns aDatumReaderfor this kind of data.- Overrides:
createDatumReaderin classGenericData
-
createDatumWriter
Description copied from class:GenericDataReturns aDatumWriterfor this kind of data.- Overrides:
createDatumWriterin classGenericData
-
get
Return the singleton instance. -
getForSchema
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- the reader schema- Returns:
- the SpecificData associated with the schema's class, or the default instance.
-
getForClass
If the given class is assignable toSpecificRecordBase, this method returns the SpecificData instance from the fieldMODEL$, in order to get the correctConversioninstances for the class. Falls back to the default instanceget()for other classes or if the field is not found.- Type Parameters:
T- .- Parameters:
c- A class- Returns:
- The SpecificData from the SpecificRecordBase instance, or the default SpecificData instance.
-
useCustomCoders
public boolean useCustomCoders()Retrieve the current value of the custom-coders feature flag. Defaults tofalse, but this default can be overridden using the system propertyorg.apache.avro.specific.use_custom_coders, and can be set dynamically byuseCustomCoders(). See invalid input: '<'a href="https://avro.apache.org/docs/current/gettingstartedjava.html#Beta+feature:+Generating+faster+code"Getting started with Java for more about this feature flag. -
setCustomCoders
public void setCustomCoders(boolean flag) Dynamically set the value of the custom-coder feature flag. SeeuseCustomCoders(). -
isEnum
Description copied from class:GenericDataCalled by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).- Overrides:
isEnumin classGenericData
-
createEnum
Description copied from class:GenericDataCalled to create an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.- Overrides:
createEnumin classGenericData
-
getEnumSchema
Description copied from class:GenericDataCalled to obtain the schema of a enum. By default calls {GenericContainer#getSchema(). May be overridden for alternate enum representations.- Overrides:
getEnumSchemain classGenericData
-
mangleFullyQualified
Utility to mangle the fully qualified class name into a valid symbol. -
mangle
Utility for template use. Adds a dollar sign to reserved words. -
mangle
Utility for template use. Adds a dollar sign to reserved words. -
mangleTypeIdentifier
Utility for template use. Adds a dollar sign to reserved words in type identifiers. -
mangleTypeIdentifier
Utility for template use. Adds a dollar sign to reserved words in type identifiers. -
mangle
Utility for template use. Adds a dollar sign to reserved words. -
mangleMethod
-
mangle
Utility for template use. Adds a dollar sign to reserved words. -
unmangle
Undoes mangling for reserved words. -
getClass
Return the class that implements a schema, or null if none exists. -
getClassName
Returns the Java class name indicated by a schema's name and namespace. -
getSchema
Find the schema for a Java type. -
createSchema
Create the schema for a Java type. -
getSchemaName
Description copied from class:GenericDataReturn the schema full name for a datum. Called byGenericData.resolveUnion(Schema,Object).- Overrides:
getSchemaNamein classGenericData
-
isStringable
True if a class should be serialized with toString(). -
isStringType
True if a class IS a string type -
getProtocol
Return the protocol for a Java interface. -
compare
Description copied from class:GenericDataComparison implementation. When equals is true, only checks for equality, not for order.- Overrides:
comparein classGenericData
-
newInstance
Create an instance of a class. If the class implementsSpecificData.SchemaConstructable, call a constructor with aSchemaparameter, otherwise use a no-arg constructor. -
createFixed
Description copied from class:GenericDataCalled to create an fixed value. May be overridden for alternate fixed representations. By default, returnsGenericFixed.- Overrides:
createFixedin classGenericData
-
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 classGenericData
-
getNewRecordSupplier
Description copied from class:GenericDatacreate a supplier that allows to get new record instances for a given schema in an optimized way- Overrides:
getNewRecordSupplierin classGenericData
-
getDecoder
Runtime utility used by generated classes. -
getEncoder
Runtime utility used by generated classes. -
createString
Description copied from class:GenericDataCalled to create an string value. May be overridden for alternate string representations.- Overrides:
createStringin classGenericData
-