Top Description Inners Fields Constructors Methods
org.apache.avro.generic

public Class GenericData

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.avro.specific.SpecificData
Imports
java.io.ByteArrayOutputStream, .IOException, java.nio.Buffer, .ByteBuffer, java.nio.charset.StandardCharsets, java.time.temporal.Temporal, java.util.AbstractList, .Arrays, .Collection, .HashMap, .IdentityHashMap, .Iterator, .LinkedHashMap, .List, .Map, .ServiceLoader, .UUID, java.util.concurrent.ConcurrentMap, org.apache.avro.AvroMissingFieldException, .AvroRuntimeException, .AvroTypeException, .Conversion, .Conversions, .JsonProperties, .LogicalType, .Schema, .Schema.Field, .Schema.Type, .UnresolvedUnionException, org.apache.avro.io.BinaryData, .BinaryDecoder, .BinaryEncoder, .DatumReader, .DatumWriter, .DecoderFactory, .EncoderFactory, .FastReaderBuilder, org.apache.avro.util.Utf8, org.apache.avro.util.internal.Accessor, com.fasterxml.jackson.databind.JsonNode, org.apache.avro.util.springframework.ConcurrentReferenceHashMap

Utilities for generic Java data. See GenericRecordBuilder for a convenient way to build GenericRecord instances.
See Also
GenericRecordBuilder

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
GenericData.Array<T>

Default implementation of an array.

public static class
GenericData.EnumSymbol

Default implementation of GenericEnumSymbol.

public static class
GenericData.Fixed

Default implementation of GenericFixed.

public static interface
public static class
GenericData.Record

Default implementation of GenericRecord.

public static enum
GenericData.StringType

Used to specify the Java type for a string schema.

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private Map<String, Conversion<?>>
private Map<Class<?>, Map<String, Conversion<?>>>
private final ConcurrentMap<Schema.Field, Object>
public static final String
private FastReaderBuilder
private boolean
private static final GenericData
private static final Map<Class<?>, String>
public static final String
protected static final String
private static final Schema
private static final String

Constructor Summary

AccessConstructor and Description
public
GenericData()

For subclasses.

public
GenericData(ClassLoader classLoader)

For subclasses.

Method Summary

Modifier and TypeMethod and Description
public void
addLogicalTypeConversion(Conversion<?>
a logical type Conversion.
conversion
)

Registers the given conversion to be used when reading and writing with this data model.

public int
compare(Object o1, Object o2, Schema s)

Compare objects according to their schema.

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

Comparison implementation.

protected int
compareMaps(final Map<?, ?> m1, final Map<?, ?> m2)

public DatumReader<D>
createDatumReader(Schema schema)

Returns a DatumReader for this kind of data.

public DatumReader<D>
createDatumReader(Schema writer, Schema reader)

Returns a DatumReader for this kind of data.

public DatumWriter<D>
createDatumWriter(Schema schema)

Returns a DatumWriter for this kind of data.

public Object
createEnum(String symbol, Schema schema)

Called to create an enum value.

public Object
createFixed(Object old, Schema schema)

Called to create an fixed value.

public Object
createFixed(Object old, byte[] bytes, Schema schema)

Called to create an fixed value.

public Object
createString(Object value)

Called to create an string value.

public <T> T

Returns:

a deep copy of the given value.
deepCopy
(Schema
the schema of the value to deep copy.
schema
,
T
the value to deep copy.
value
)

Makes a deep copy of a value given its schema.

private Object
deepCopyRaw(Schema schema, Object value)

public static GenericData
get()

Return the singleton instance.

protected Collection<E>
getArrayAsCollection(Object datum)

Called to access an array as a collection.

public ClassLoader
getClassLoader()

Return the class loader that's used (by subclasses).

public <T> Conversion<T>

Returns:

the first registered conversion for the class, or null
getConversionByClass
(Class<T>
a Class
datumClass
)

Returns the first conversion found for the given class.

public <T> Conversion<T>

Returns:

the conversion for the class and logical type, or null
getConversionByClass
(Class<T>
a Class
datumClass
,
LogicalType
a LogicalType
logicalType
)

Returns the conversion for the given class and logical type.

public <T> Conversion<T>

Returns:

the conversion for the logical type, or null
getConversionFor
(LogicalType
a logical type
logicalType
)

Returns the Conversion for the given logical type.

public Collection<Conversion<?>>
public Object

Returns:

the default value associated with the given field, or null if none is specified in the schema.
getDefaultValue
(Schema.Field
the field whose default value should be retrieved.
field
)

Gets the default value of the given field, if any.

protected Schema
getEnumSchema(Object enu)

Called to obtain the schema of a enum.

public FastReaderBuilder
public Object
getField(Object record, String name, int position)

Called by GenericDatumReader#readRecord to retrieve a record field value from a reused instance.

protected Object
getField(Object record, String name, int pos, Object state)

Version of getField that has state.

protected Schema
getFixedSchema(Object fixed)

Called to obtain the schema of a fixed.

public GenericData.InstanceSupplier
getNewRecordSupplier(Schema schema)

create a supplier that allows to get new record instances for a given schema in an optimized way

protected Map<Class<?>, String>
getPrimitiveTypeCache()

Called to obtain the primitive type cache.

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 to getField(Object, String, int, Object) and setField(Object, String, int, Object, Object) on the same record.

protected String
getSchemaName(Object datum)

Return the schema full name for a datum.

public int
hashCode(Object o, Schema s)

Compute a hash code according to a schema, consistent with compare(Object, Object, Schema).

protected int
hashCodeAdd(int hashCode, Object o, Schema s)

Add the hash code for an object into an accumulated hash code.

public Schema
induce(Object datum)

Create a schema given an example datum.

protected boolean
protected boolean
isArray(Object datum)

Called by the default implementation of instanceOf.

protected boolean
isBoolean(Object datum)

Called by the default implementation of instanceOf.

protected boolean
isBytes(Object datum)

Called by the default implementation of instanceOf.

protected boolean
isDouble(Object datum)

Called by the default implementation of instanceOf.

protected boolean
isEnum(Object datum)

Called by the default implementation of instanceOf.

public boolean
protected boolean
isFixed(Object datum)

Called by the default implementation of instanceOf.

protected boolean
isFloat(Object datum)

Called by the default implementation of instanceOf.

protected boolean
isInteger(Object datum)

Called by the default implementation of instanceOf.

protected boolean
isLong(Object datum)

Called by the default implementation of instanceOf.

protected boolean
isMap(Object datum)

Called by the default implementation of instanceOf.

private boolean
protected boolean
isRecord(Object datum)

Called by the default implementation of instanceOf.

protected boolean
isString(Object datum)

Called by the default implementation of instanceOf.

private boolean
private void
loadConversions()

Use the Java 6 ServiceLoader to load conversions.

public Object
newArray(Object old, int size, Schema schema)

public Object
newMap(Object old, int size)

Called to create new array instances.

public Object
newRecord(Object old, Schema schema)

Called to create new record instances.

public int
resolveUnion(Schema union, Object datum)

Return the index for a datum within a union.

public GenericData
setFastReaderEnabled(boolean flag)

public void
setField(Object record, String name, int position, Object value)

Called by GenericDatumReader#readRecord to set a record fields value to a record instance.

protected void
setField(Object record, String name, int position, Object value, Object state)

Version of setField that has state.

public static void
setStringType(Schema s, GenericData.StringType stringType)

Set the Java type to be used when reading this schema.

public String
toString(Object datum)

Renders a Java datum as JSON.

protected void
toString(Object datum, StringBuilder buffer, IdentityHashMap<Object, Object> seenObjects)

Renders a Java datum as JSON.

public boolean
validate(Schema schema, Object datum)

Returns true if a Java datum matches a schema.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait