@@ -0,0 +1,1700 @@
+package pl.edu.icm.sparkutils.avro;%0A%0Aimport java.io.Serializable;%0Aimport java.util.ArrayList;%0Aimport java.util.Collection;%0A%0Aimport org.apache.avro.generic.GenericData;%0Aimport org.apache.spark.serializer.KryoRegistrator;%0A%0Aimport com.esotericsoftware.kryo.Kryo;%0Aimport com.esotericsoftware.kryo.io.Input;%0Aimport com.esotericsoftware.kryo.serializers.CollectionSerializer;%0A%0A/**%0A * Registrator for kryo serializer. It adds support for avro generated classes.%0A * %0A * @author madryk%0A * %0A * @see https://issues.apache.org/jira/browse/SPARK-3601%0A */%0Apublic class AvroCompatibleKryoRegistrator implements KryoRegistrator %7B%0A%0A%09@SuppressWarnings(%7B %22unchecked%22, %22rawtypes%22 %7D)%0A    @Override%0A%09public void registerClasses(Kryo kryo) %7B%0A%09%09kryo.register(GenericData.Array.class, new SpecificInstanceCollectionSerializer(ArrayList.class));%0A%09%7D%0A%0A%0A%09/**%0A%09 * Special serializer for Java collections enforcing certain instance types.%0A%09 * Avro is serializing collections with an %22GenericData.Array%22 type. Kryo is not able to handle%0A%09 * this type, so we use ArrayLists.%0A%09 */%0A%09public static class SpecificInstanceCollectionSerializer%3CT extends java.util.ArrayList%3C?%3E%3E extends CollectionSerializer implements Serializable %7B%0A%09%09private static final long serialVersionUID = 1L;%0A%09%09private Class%3CT%3E type;%0A%0A%09%09public SpecificInstanceCollectionSerializer(Class%3CT%3E type) %7B%0A%09%09%09this.type = type;%0A%09%09%7D%0A%0A%09%09@SuppressWarnings(%22rawtypes%22)%0A        @Override%0A%09%09protected Collection create(Kryo kryo, Input input, Class%3CCollection%3E type) %7B%0A%09%09%09return kryo.newInstance(this.type);%0A%09%09%7D%0A%0A%09%09@SuppressWarnings(%22rawtypes%22)%0A        @Override%0A%09%09protected Collection createCopy(Kryo kryo, Collection original) %7B%0A%09%09%09return kryo.newInstance(this.type);%0A%09%09%7D%0A%09%7D%0A%7D%0A

Create AvroCompatibleKryoRegistrator