Top Description Constructors Methods
org.apache.avro

public abstract Class Conversion<T>

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.avro.Conversions.UUIDConversion, org.apache.avro.Conversions.DecimalConversion, org.apache.avro.data.TimeConversions.DateConversion, org.apache.avro.data.TimeConversions.TimeMillisConversion, org.apache.avro.data.TimeConversions.TimeMicrosConversion, org.apache.avro.data.TimeConversions.TimestampMillisConversion, org.apache.avro.data.TimeConversions.TimestampMicrosConversion, org.apache.avro.data.TimeConversions.LocalTimestampMillisConversion, org.apache.avro.data.TimeConversions.LocalTimestampMicrosConversion
Annotations
@SuppressWarnings:unused
Type Parameters
<T>
a Java type that can represent the named logical type
Imports
java.nio.ByteBuffer, java.util.Collection, .Map, .ServiceLoader, org.apache.avro.generic.GenericData, .GenericEnumSymbol, .GenericFixed, .IndexedRecord

Conversion between generic and logical type instances.

Instances of this class can be added to GenericData to convert a logical type to a particular representation. This can be done manually, using GenericData#addLogicalTypeConversion(Conversion), or automatically. This last option uses the Java ServiceLoader, and requires the implementation to be a public class with a public no-arg constructor, be named in a file called /META-INF/services/org.apache.avro.Conversion, and both must available in the classpath.

Implementations must provide:

Subclasses must also override the conversion methods for Avro's base types that are valid for the logical type, or else risk causing UnsupportedOperationException at runtime.

Optionally, use getRecommendedSchema() to provide a Schema that will be used when generating a Schema for the class. This is useful when using ReflectData or ProtobufData, for example.

See Also
ServiceLoader

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

a String for the body of the setter method
adjustAndSetValue
(String
the name of the variable holding the converted value
varName
,
String
the name of the parameter with the new converted value
valParamName
)

Certain logical types may require adjusting the code within the "setter" methods to make sure the data that is set is properly formatted.

public T
fromArray(Collection<?> value, Schema schema, LogicalType type)

public T
fromBoolean(Boolean value, Schema schema, LogicalType type)

public T
fromBytes(ByteBuffer value, Schema schema, LogicalType type)

public T
public T
fromDouble(Double value, Schema schema, LogicalType type)

public T
public T
public T
fromFloat(Float value, Schema schema, LogicalType type)

public T
fromInt(Integer value, Schema schema, LogicalType type)

public T
fromLong(Long value, Schema schema, LogicalType type)

public T
fromMap(Map<?, ?> value, Schema schema, LogicalType type)

public T
public abstract Class<T>

Returns:

a Java class returned by from methods and accepted by to methods
getConvertedType
()

Return the Java class representing the logical type.

public abstract String

Returns:

a String logical type name
getLogicalTypeName
()

Return the logical type this class converts.

public Schema
public Collection<?>
toArray(T value, Schema schema, LogicalType type)

public Boolean
toBoolean(T value, Schema schema, LogicalType type)

public ByteBuffer
toBytes(T value, Schema schema, LogicalType type)

public CharSequence
toCharSequence(T value, Schema schema, LogicalType type)

public Double
toDouble(T value, Schema schema, LogicalType type)

public GenericEnumSymbol<?>
toEnumSymbol(T value, Schema schema, LogicalType type)

public GenericFixed
toFixed(T value, Schema schema, LogicalType type)

public Float
toFloat(T value, Schema schema, LogicalType type)

public Integer
toInt(T value, Schema schema, LogicalType type)

public Long
toLong(T value, Schema schema, LogicalType type)

public Map<?, ?>
toMap(T value, Schema schema, LogicalType type)

public IndexedRecord
toRecord(T value, Schema schema, LogicalType type)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Conversionback to summary
public Conversion()

Method Detail

adjustAndSetValueback to summary
public String adjustAndSetValue(String varName, String valParamName)

Certain logical types may require adjusting the code within the "setter" methods to make sure the data that is set is properly formatted. This method allows the Conversion to generate custom setter code if required.

Parameters
varName:String

the name of the variable holding the converted value

valParamName:String

the name of the parameter with the new converted value

Returns:String

a String for the body of the setter method

fromArrayback to summary
public T fromArray(Collection<?> value, Schema schema, LogicalType type)
fromBooleanback to summary
public T fromBoolean(Boolean value, Schema schema, LogicalType type)
fromBytesback to summary
public T fromBytes(ByteBuffer value, Schema schema, LogicalType type)
fromCharSequenceback to summary
public T fromCharSequence(CharSequence value, Schema schema, LogicalType type)
fromDoubleback to summary
public T fromDouble(Double value, Schema schema, LogicalType type)
fromEnumSymbolback to summary
public T fromEnumSymbol(GenericEnumSymbol<?> value, Schema schema, LogicalType type)
fromFixedback to summary
public T fromFixed(GenericFixed value, Schema schema, LogicalType type)
fromFloatback to summary
public T fromFloat(Float value, Schema schema, LogicalType type)
fromIntback to summary
public T fromInt(Integer value, Schema schema, LogicalType type)
fromLongback to summary
public T fromLong(Long value, Schema schema, LogicalType type)
fromMapback to summary
public T fromMap(Map<?, ?> value, Schema schema, LogicalType type)
fromRecordback to summary
public T fromRecord(IndexedRecord value, Schema schema, LogicalType type)
getConvertedTypeback to summary
public abstract Class<T> getConvertedType()

Return the Java class representing the logical type.

Returns:Class<T>

a Java class returned by from methods and accepted by to methods

getLogicalTypeNameback to summary
public abstract String getLogicalTypeName()

Return the logical type this class converts.

Returns:String

a String logical type name

getRecommendedSchemaback to summary
public Schema getRecommendedSchema()
toArrayback to summary
public Collection<?> toArray(T value, Schema schema, LogicalType type)
toBooleanback to summary
public Boolean toBoolean(T value, Schema schema, LogicalType type)
toBytesback to summary
public ByteBuffer toBytes(T value, Schema schema, LogicalType type)
toCharSequenceback to summary
public CharSequence toCharSequence(T value, Schema schema, LogicalType type)
toDoubleback to summary
public Double toDouble(T value, Schema schema, LogicalType type)
toEnumSymbolback to summary
public GenericEnumSymbol<?> toEnumSymbol(T value, Schema schema, LogicalType type)
toFixedback to summary
public GenericFixed toFixed(T value, Schema schema, LogicalType type)
toFloatback to summary
public Float toFloat(T value, Schema schema, LogicalType type)
toIntback to summary
public Integer toInt(T value, Schema schema, LogicalType type)
toLongback to summary
public Long toLong(T value, Schema schema, LogicalType type)
toMapback to summary
public Map<?, ?> toMap(T value, Schema schema, LogicalType type)
toRecordback to summary
public IndexedRecord toRecord(T value, Schema schema, LogicalType type)