javasupercsv

How to apply quote character on every field using custom CsvPreference


I'm using super csv https://super-csv.github.io/super-csv/apidocs/org/supercsv/prefs/CsvPreference.html to create csv file.

It works great. But I need to set quotes around all fields, not only those that have a comma. So instead of

1,2,test,"something,test", 1,x

I need this

"1","2","test","something,test","1","x"

Question: WHAT SHOULD I PUT HERE TO MAKE IT WORK???????????

    private static final CsvPreference PIPE_DELIMITED = 
       new CsvPreference.Builder(WHAT SHOULD I PUT HERE TO MAKE IT WORK???????????).build();

Solution

  • Have you tried something like:

    private static final CsvPreference PIPE_DELIMITED = 
           new CsvPreference.Builder(CsvPreference.STANDARD_PREFERENCE)
                            .useQuoteMode(new AlwaysQuoteMode()
                            .build();