@Test
public void testCsvEncoder() throws IOException, CsvParseException {

  Schema rowschema = SchemaBuilder.record("CsvRow").fields()
          .requiredBoolean("boolField")
          .requiredBytes("bytesField")
          .requiredInt("intField")
          .requiredLong("longField")
          .requiredString("stringField")
          .requiredDouble("doubleField")
          .name("recordField").type(PackageInfo.getClassSchema()).noDefault()
          .nullableString("nullableString", null)
          .name("enumField").type(Schema.createEnum("myEnum", "", "", Arrays.asList("e1", "e2"))).noDefault()
          .endRecord();
  List<GenericRecord> list = testArray(rowschema);
  Schema csvSchema = Schema.createArray(rowschema);
  CharSeparatedValues csv = new CharSeparatedValues(',');
  StringWriter writeTo = new StringWriter();
  CsvEncoder encoder = new CsvEncoder(csv.writer(writeTo), csvSchema);
  encoder.writeHeader();
  DatumWriter writer = new GenericDatumWriter(csvSchema);
  writer.write(list, encoder);
  encoder.flush();
  LOG.debug("written:", writeTo);
  StringReader reader = new StringReader(writeTo.toString());
  CsvDecoder decoder = new CsvDecoder(csv.reader(reader), csvSchema);
  decoder.skipHeader();
  GenericDatumReader dr = new GenericDatumReader(csvSchema);
  Object parsed = dr.read(null, decoder);
  LOG.debug("parser:", parsed);
}