I am using jackson-dataformat-csv
to export a POJO collection to CSV as follows:
CsvSchema.Builder schemaBuilder = CsvSchema.builder()
.addColumn("id")
.addColumn("name")
etc...
CsvSchema schema = schemaBuilder.build().withHeader();
CsvMapper mapper = new CsvMapper();
mapper.enable(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS);
String csv = mapper.writer(schema).writeValueAsString(pojoCollection);
I want to inspect every field value before it is written to CSV and optionally modify that value to prevent formulas or other content that Excel, Sheets, etc might execute. For example if a value starts with @
or =
then I might prepend the '
character to that value to prevent execution.
How can I configure CsvMapper
so that I get a callback for each value written to CSV?