KryoAvroRegistrator implements KryoRegistrator { public void registerClasses(Kryo kryo) { String classesString = System.getProperty(KITE_AVRO_CLASSES); if (classesString == null || classesString.isEmpty()) { LOGGER.info("No Avro classes set in property {}.", KITE_AVRO_CLASSES); } else { LOGGER.info("Registring Avro classes {}.", classesString); String[] classes = classesString.split(","); for(String className: classes) { Class cls = null; try { cls = Thread.currentThread().getContextClassLoader().loadClass(className); } catch (ClassNotFoundException e) { throw new AppException(e); } kryo.register(cls, new KryoAvroSerializer(cls)); } } }  void registerClasses(Kryo kryo); static final String KITE_AVRO_CLASSES; }
@Test public void testRegistrator() { System.setProperty(KryoAvroRegistrator.KITE_AVRO_CLASSES, SmallEvent.class.getName()); Kryo kryo = new Kryo(); new KryoAvroRegistrator().registerClasses(kryo); Serializer serializer = kryo.getSerializer(SmallEvent.class); Assert.assertNotNull(serializer); Output output = new Output(1024); SmallEvent testEvent = SmallEvent.newBuilder() .setUserId(1) .setSessionId("123") .build(); kryo.writeObject(output, testEvent); byte [] bytes = output.toBytes(); Input input = new Input(bytes); SmallEvent result = kryo.readObject(input, SmallEvent.class); Assert.assertEquals(testEvent, result); }