Class AvroObjectConverter
- java.lang.Object
-
- net.sourceforge.jbizmo.commons.avro.util.AvroObjectConverter
-
public class AvroObjectConverter extends Object
Utility class that converts Avro objects into similar objects and vice versa by using reflection. The converter methods expect that both classes have the same fields with the same name. The respective field types can be different. When converting an object into its Avro counterpart the fields of type
DateandGregorianCalendarare converted toInstant. The converter also supports converting complex structures (e.g. an Avro object that contains a field of typeSpecificRecordBaseor a list withSpecificRecordBaseobjects). If different enum fields must be converted the literals of both enums must be equal!Copyright 2021 (C) by Martin Ganserer
- Version:
- 1.0.0
- Author:
- Martin Ganserer
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends org.apache.avro.specific.SpecificRecordBase>
TtoAvro(Object object, Class<T> avroType)Convert the given object into an Avro objectstatic <T extends org.apache.avro.specific.SpecificRecordBase,S>
List<T>toAvroList(List<S> objectList, Class<T> avroType)Convert an object list into a list of Avro objectsstatic <T> TtoObject(org.apache.avro.specific.SpecificRecordBase record, Class<T> type)Convert the given Avro object into an object of the desired typestatic <T,S extends org.apache.avro.specific.SpecificRecordBase>
List<T>toObjectList(List<S> avroList, Class<T> objectType)Convert an Avro object list into a list of objects
-
-
-
Method Detail
-
toAvro
public static <T extends org.apache.avro.specific.SpecificRecordBase> T toAvro(Object object, Class<T> avroType)
Convert the given object into an Avro object- Type Parameters:
T- the desired Avro type- Parameters:
object- the source objectavroType- the Avro class- Returns:
- the converted Avro object
- Throws:
AvroObjectConversionException- if the conversion has failed
-
toAvroList
public static <T extends org.apache.avro.specific.SpecificRecordBase,S> List<T> toAvroList(List<S> objectList, Class<T> avroType)
Convert an object list into a list of Avro objects- Type Parameters:
T- the desired Avro typeS- the type of the objects that are contained in the list- Parameters:
objectList- the list that contains all objects that should be convertedavroType- the Avro class- Returns:
- a list with the converted Avro objects
- Throws:
AvroObjectConversionException- if the conversion has failed
-
toObject
public static <T> T toObject(org.apache.avro.specific.SpecificRecordBase record, Class<T> type)Convert the given Avro object into an object of the desired type- Type Parameters:
T- the desired object type- Parameters:
record- the Avro object to be convertedtype- the object class- Returns:
- the target object
- Throws:
AvroObjectConversionException- if the conversion has failed
-
toObjectList
public static <T,S extends org.apache.avro.specific.SpecificRecordBase> List<T> toObjectList(List<S> avroList, Class<T> objectType)
Convert an Avro object list into a list of objects- Type Parameters:
T- the desired object typeS- the type of the objects that are contained in the list- Parameters:
avroList- the list that contains all Avro objects that should be convertedobjectType- the object class- Returns:
- a list with the converted objects
- Throws:
AvroObjectConversionException- if the conversion has failed
-
-