class AvroSerializer {

  public byte[] serialize(GenericContainer record) throws IOException {
    if (record != null) {
      DatumWriter<GenericContainer> datumWriter = new GenericDatumWriter<>(record.getSchema());
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      DataFileWriter<GenericContainer> writer = new DataFileWriter<>(datumWriter);
      writer.create(record.getSchema(), out);
      writer.append(record);
      writer.close();
      out.close();
      return out.toByteArray();
    } else {
      return null;
    }
  }

}