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:
getConvertedType(): get the Java class used for the logical
typegetLogicalTypeName(): get the logical type this implements
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.
ServiceLoader
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: a String for the body of the setter methodthe 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 | |
| public T | |
| public T | |
| public T | |
| public T | |
| public T | |
| public T | |
| public T | |
| public T | |
| public T | |
| public T | |
| public T | |
| public abstract Class | Returns: a Java class returned by from methods and accepted by to methodsReturn the Java class representing the logical type. |
| public abstract String | |
| public Schema | |
| public Collection | |
| public Boolean | |
| public ByteBuffer | |
| public CharSequence | |
| public Double | |
| public GenericEnumSymbol | |
| public GenericFixed | |
| public Float | |
| public Integer | |
| public Long | |
| public Map | |
| public IndexedRecord |
| Conversion | back to summary |
|---|---|
| public Conversion() | |
| adjustAndSetValue | back 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. | |
| fromArray | back to summary |
|---|---|
| public T fromArray(Collection<?> value, Schema schema, LogicalType type) | |
| fromBoolean | back to summary |
|---|---|
| public T fromBoolean(Boolean value, Schema schema, LogicalType type) | |
| fromBytes | back to summary |
|---|---|
| public T fromBytes(ByteBuffer value, Schema schema, LogicalType type) | |
| fromCharSequence | back to summary |
|---|---|
| public T fromCharSequence(CharSequence value, Schema schema, LogicalType type) | |
| fromDouble | back to summary |
|---|---|
| public T fromDouble(Double value, Schema schema, LogicalType type) | |
| fromEnumSymbol | back to summary |
|---|---|
| public T fromEnumSymbol(GenericEnumSymbol<?> value, Schema schema, LogicalType type) | |
| fromFixed | back to summary |
|---|---|
| public T fromFixed(GenericFixed value, Schema schema, LogicalType type) | |
| fromFloat | back to summary |
|---|---|
| public T fromFloat(Float value, Schema schema, LogicalType type) | |
| fromInt | back to summary |
|---|---|
| public T fromInt(Integer value, Schema schema, LogicalType type) | |
| fromLong | back to summary |
|---|---|
| public T fromLong(Long value, Schema schema, LogicalType type) | |
| fromMap | back to summary |
|---|---|
| public T fromMap(Map<?, ?> value, Schema schema, LogicalType type) | |
| fromRecord | back to summary |
|---|---|
| public T fromRecord(IndexedRecord value, Schema schema, LogicalType type) | |
| getConvertedType | back to summary |
|---|---|
| public abstract Class Return the Java class representing the logical type.
| |
| getLogicalTypeName | back to summary |
|---|---|
| public abstract String getLogicalTypeName() Return the logical type this class converts.
| |
| getRecommendedSchema | back to summary |
|---|---|
| public Schema getRecommendedSchema() | |
| toArray | back to summary |
|---|---|
| public Collection | |
| toBoolean | back to summary |
|---|---|
| public Boolean toBoolean(T value, Schema schema, LogicalType type) | |
| toBytes | back to summary |
|---|---|
| public ByteBuffer toBytes(T value, Schema schema, LogicalType type) | |
| toCharSequence | back to summary |
|---|---|
| public CharSequence toCharSequence(T value, Schema schema, LogicalType type) | |
| toDouble | back to summary |
|---|---|
| public Double toDouble(T value, Schema schema, LogicalType type) | |
| toEnumSymbol | back to summary |
|---|---|
| public GenericEnumSymbol | |
| toFixed | back to summary |
|---|---|
| public GenericFixed toFixed(T value, Schema schema, LogicalType type) | |
| toFloat | back to summary |
|---|---|
| public Float toFloat(T value, Schema schema, LogicalType type) | |
| toInt | back to summary |
|---|---|
| public Integer toInt(T value, Schema schema, LogicalType type) | |
| toLong | back to summary |
|---|---|
| public Long toLong(T value, Schema schema, LogicalType type) | |
| toMap | back to summary |
|---|---|
| public Map | |
| toRecord | back to summary |
|---|---|
| public IndexedRecord toRecord(T value, Schema schema, LogicalType type) | |