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
Modifier and TypeClassDescriptionstatic interface
Tag 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
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final char
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.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
ConstructorDescriptionFor subclasses.SpecificData
(ClassLoader classLoader) Construct with a specific classloader. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.createEnum
(String symbol, Schema schema) Called to create an enum value.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.createString
(Object value) Called to create an string value.static SpecificData
get()
Return the singleton instance.Return the class that implements a schema, or null if none exists.static String
getClassName
(Schema schema) Returns the Java class name indicated by a schema's name and namespace.static BinaryDecoder
Runtime utility used by generated classes.static BinaryEncoder
getEncoder
(ObjectOutput out) Runtime utility used by generated classes.protected Schema
getEnumSchema
(Object datum) Called to obtain the schema of a enum.static <T> SpecificData
getForClass
(Class<T> c) If the given class is assignable toSpecificRecordBase
, this method returns the SpecificData instance from the fieldMODEL$
, in order to get the correctConversion
instances for the class.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.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 String
getSchemaName
(Object datum) Return the schema full name for a datum.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().protected boolean
isStringType
(Class<?> c) True if a class IS a string typestatic String
Utility for template use.static String
Utility for template use.static String
Utility for template use.static String
Utility for template use.static String
mangleFullyQualified
(String fullName) Utility to mangle the fully qualified class name into a valid symbol.static String
mangleMethod
(String word, boolean isError) static String
mangleTypeIdentifier
(String word) Utility for template use.static String
mangleTypeIdentifier
(String word, boolean isError) Utility for template use.static Object
newInstance
(Class c, Schema s) Create an instance of a class.Called to create new record instances.void
setCustomCoders
(boolean flag) Dynamically set the value of the custom-coder feature flag.protected static String
Undoes mangling for reserved words.boolean
Retrieve 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:GenericData
Returns aDatumReader
for this kind of data.- Overrides:
createDatumReader
in classGenericData
-
createDatumReader
Description copied from class:GenericData
Returns aDatumReader
for this kind of data.- Overrides:
createDatumReader
in classGenericData
-
createDatumWriter
Description copied from class:GenericData
Returns aDatumWriter
for this kind of data.- Overrides:
createDatumWriter
in 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 correctConversion
instances 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:GenericData
Called by the default implementation ofGenericData.instanceOf(org.apache.avro.Schema, java.lang.Object)
.- Overrides:
isEnum
in classGenericData
-
createEnum
Description copied from class:GenericData
Called to create an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.- Overrides:
createEnum
in classGenericData
-
getEnumSchema
Description copied from class:GenericData
Called to obtain the schema of a enum. By default calls {GenericContainer#getSchema(). May be overridden for alternate enum representations.- Overrides:
getEnumSchema
in 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:GenericData
Return the schema full name for a datum. Called byGenericData.resolveUnion(Schema,Object)
.- Overrides:
getSchemaName
in 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:GenericData
Comparison implementation. When equals is true, only checks for equality, not for order.- Overrides:
compare
in classGenericData
-
newInstance
Create an instance of a class. If the class implementsSpecificData.SchemaConstructable
, call a constructor with aSchema
parameter, otherwise use a no-arg constructor. -
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 classGenericData
-
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 classGenericData
-
getNewRecordSupplier
Description copied from class:GenericData
create a supplier that allows to get new record instances for a given schema in an optimized way- Overrides:
getNewRecordSupplier
in classGenericData
-
getDecoder
Runtime utility used by generated classes. -
getEncoder
Runtime utility used by generated classes. -
createString
Description copied from class:GenericData
Called to create an string value. May be overridden for alternate string representations.- Overrides:
createString
in classGenericData
-