ApacheCommonCsvRecordMarshaller implements RecordMarshaller<P, String> { @Override public StringRecord processRecord(final Record<P> record) throws Exception { StringWriter stringWriter = new StringWriter(); CSVPrinter csvPrinter = new CSVPrinter(stringWriter, csvFormat); Iterable<Object> iterable = fieldExtractor.extractFields(record.getPayload()); csvPrinter.printRecord(iterable); csvPrinter.flush(); csvPrinter.close(); return new StringRecord(record.getHeader(), stringWriter.toString()); } ApacheCommonCsvRecordMarshaller(final Class<P> type, final String... fields);  ApacheCommonCsvRecordMarshaller(FieldExtractor<P> fieldExtractor); @Override StringRecord processRecord(final Record<P> record); void setDelimiter(char delimiter); void setQualifier(char qualifier); static final char DEFAULT_DELIMITER; static final char DEFAULT_QUALIFIER; }
@Test public void marshal() throws Exception { Foo foo = new Foo(); foo.setFirstName("foo"); foo.setLastName("bar"); when(record.getPayload()).thenReturn(foo); String expected = "'foo';'bar';'false'"; String actual = marshaller.processRecord(record).getPayload(); assertThat(actual).isEqualTo(expected); }