/** * Serialize an object to a byte array * * @param obj The object to serialize * @param writer The datum writer for the class * @return Serialized row */ public static <T> byte[] serializeAvroObject(T obj, DatumWriter<T> writer) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Encoder encoder = EncoderFactory.get().binaryEncoder(out, null); try { writer.write(obj, encoder); encoder.flush(); } catch (IOException e) { throw serializationError(obj, e); } return out.toByteArray(); }