org.apache.avro.specific

## Class SpecificData

- java.lang.Object
- - org.apache.avro.generic.GenericData
  - - org.apache.avro.specific.SpecificData

Direct Known Subclasses:
  ReflectData

    public class SpecificData
    extends GenericData

Utilities for generated Java classes and interfaces.

### Nested Class Summary

Nested Classes
`static interface` `SpecificData.SchemaConstructable` 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.Array<T>, GenericData.EnumSymbol, GenericData.Fixed, GenericData.InstanceSupplier, GenericData.Record, GenericData.StringType`

### Field Summary

Fields
`static String` `CLASS_PROP`
`static String` `ELEMENT_PROP`
`static String` `KEY_CLASS_PROP`
`static char` `RESERVED_WORD_ESCAPE_CHAR`
`static Set<String>` `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.
`protected Set<Class>` `stringableClasses` 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

Constructors
Constructor and Description
`SpecificData()` For subclasses.
`SpecificData(ClassLoader classLoader)` Construct with a specific classloader.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected int` `compare(Object o1, Object o2, Schema s, boolean eq)` Comparison implementation.
`DatumReader` `createDatumReader(Schema schema)` Returns a `DatumReader` for this kind of data.
`DatumReader` `createDatumReader(Schema writer, Schema reader)` Returns a `DatumReader` for this kind of data.
`DatumWriter` `createDatumWriter(Schema schema)` Returns a `DatumWriter` for this kind of data.
`Object` `createEnum(String symbol, Schema schema)` Called to create an enum value.
`Object` `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.
`Object` `createString(Object value)` Called to create an string value.
`static SpecificData` `get()` Return the singleton instance.
`Class` `getClass(Schema schema)` 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` `getDecoder(ObjectInput in)` 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 to `SpecificRecordBase`, this method returns the SpecificData instance from the field `MODEL$`, in order to get the correct `Conversion` 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.
`GenericData.InstanceSupplier` `getNewRecordSupplier(Schema schema)` create a supplier that allows to get new record instances for a given schema in an optimized way
`Protocol` `getProtocol(Class iface)` Return the protocol for a Java interface.
`Schema` `getSchema(Type type)` Find the schema for a Java type.
`protected String` `getSchemaName(Object datum)` Return the schema full name for a datum.
`protected boolean` `isEnum(Object datum)` Called by the default implementation of `GenericData.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 type
`static Object` `newInstance(Class c, Schema s)` Create an instance of a class.
`Object` `newRecord(Object old, Schema schema)` Called to create new record instances.
`void` `setCustomCoders(boolean flag)` Dynamically set the value of the custom-coder feature flag.
`protected static String` `unmangle(String word)` Undoes mangling for reserved words.
`boolean` `useCustomCoders()` 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, hashCodeAdd, induce, instanceOf, isArray, isBoolean, isBytes, isDouble, isFastReaderEnabled, isFixed, isFloat, isInteger, isLong, isMap, isRecord, isString, newArray, newMap, resolveUnion, setFastReaderEnabled, setField, setField, setStringType, toString, toString, validate`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### CLASS_PROP

    public static final String CLASS_PROP

See Also:
  Constant Field Values

#### KEY_CLASS_PROP

    public static final String KEY_CLASS_PROP

See Also:
  Constant Field Values

#### ELEMENT_PROP

    public static final String ELEMENT_PROP

See Also:
  Constant Field Values

#### RESERVED_WORD_ESCAPE_CHAR

    public static final char RESERVED_WORD_ESCAPE_CHAR

See Also:
  Constant Field Values

#### RESERVED_WORDS

    public static final Set<String> 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.

#### stringableClasses

    protected Set<Class> 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 Detail

#### SpecificData

    public SpecificData()

For subclasses. Applications normally use `get()`.

#### SpecificData

    public SpecificData(ClassLoader classLoader)

Construct with a specific classloader.

### Method Detail

#### createDatumReader

    public DatumReader createDatumReader(Schema schema)

Description copied from class: `GenericData`
Returns a `DatumReader` for this kind of data.

Overrides:
  `createDatumReader` in class `GenericData`

#### createDatumReader

    public DatumReader createDatumReader(Schema writer,
                                         Schema reader)

Description copied from class: `GenericData`
Returns a `DatumReader` for this kind of data.

Overrides:
  `createDatumReader` in class `GenericData`

#### createDatumWriter

    public DatumWriter createDatumWriter(Schema schema)

Description copied from class: `GenericData`
Returns a `DatumWriter` for this kind of data.

Overrides:
  `createDatumWriter` in class `GenericData`

#### get

    public static SpecificData get()

Return the singleton instance.

#### getForSchema

    public 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.

Parameters:
  `reader` - the reader schema
Returns:
  the SpecificData associated with the schema's class, or the default instance.

#### getForClass

    public static <T> SpecificData getForClass(Class<T> c)

If the given class is assignable to `SpecificRecordBase`, this method returns the SpecificData instance from the field `MODEL$`, in order to get the correct `Conversion` instances for the class. Falls back to the default instance `get()` 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 to `false`, but this default can be overridden using the system property `org.apache.avro.specific.use_custom_coders`, and can be set dynamically by `useCustomCoders()`. See for more about this feature flag.

#### setCustomCoders

    public void setCustomCoders(boolean flag)

Dynamically set the value of the custom-coder feature flag. See `useCustomCoders()`.

#### isEnum

    protected boolean isEnum(Object datum)

Description copied from class: `GenericData`
Called by the default implementation of `GenericData.instanceOf(org.apache.avro.Schema, java.lang.Object)`.

Overrides:
  `isEnum` in class `GenericData`

#### createEnum

    public Object createEnum(String symbol,
                             Schema schema)

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 class `GenericData`

#### getEnumSchema

    protected Schema getEnumSchema(Object datum)

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 class `GenericData`

#### unmangle

    protected static String unmangle(String word)

Undoes mangling for reserved words.

#### getClass

    public Class getClass(Schema schema)

Return the class that implements a schema, or null if none exists.

#### getClassName

    public static String getClassName(Schema schema)

Returns the Java class name indicated by a schema's name and namespace.

#### getSchema

    public Schema getSchema(Type type)

Find the schema for a Java type.

#### createSchema

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

Create the schema for a Java type.

#### getSchemaName

    protected String getSchemaName(Object datum)

Description copied from class: `GenericData`
Return the schema full name for a datum. Called by `GenericData.resolveUnion(Schema,Object)`.

Overrides:
  `getSchemaName` in class `GenericData`

#### isStringable

    protected boolean isStringable(Class<?> c)

True if a class should be serialized with toString().

#### isStringType

    protected boolean isStringType(Class<?> c)

True if a class IS a string type

#### getProtocol

    public Protocol getProtocol(Class iface)

Return the protocol for a Java interface.

#### compare

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

Description copied from class: `GenericData`
Comparison implementation. When equals is true, only checks for equality, not for order.

Overrides:
  `compare` in class `GenericData`

#### newInstance

    public static Object newInstance(Class c,
                                     Schema s)

Create an instance of a class. If the class implements `SpecificData.SchemaConstructable`, call a constructor with a `Schema` parameter, otherwise use a no-arg constructor.

#### createFixed

    public Object createFixed(Object old,
                              Schema schema)

Description copied from class: `GenericData`
Called to create an fixed value. May be overridden for alternate fixed representations. By default, returns `GenericFixed`.

Overrides:
  `createFixed` in class `GenericData`

#### newRecord

    public Object newRecord(Object old,
                            Schema schema)

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 a `GenericData.Record`.

Overrides:
  `newRecord` in class `GenericData`

#### getNewRecordSupplier

    public GenericData.InstanceSupplier getNewRecordSupplier(Schema schema)

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 class `GenericData`

#### getDecoder

    public static BinaryDecoder getDecoder(ObjectInput in)

Runtime utility used by generated classes.

#### getEncoder

    public static BinaryEncoder getEncoder(ObjectOutput out)

Runtime utility used by generated classes.

#### createString

    public Object createString(Object value)

Description copied from class: `GenericData`
Called to create an string value. May be overridden for alternate string representations.

Overrides:
  `createString` in class `GenericData`