如何配置 Super CSV 以引用除列名以外的所有值?

How to configure Super CSV to quote all values except column names?

要求是:

例如

Name, Age, Location
"A","154","California"
"B","2","New York"

如何创建这样的 SuperCSV 写入首选项?

使用以下自定义报价模式:

public class AllExceptHeaderQuoteMode implements QuoteMode {

    @Override
    public boolean quotesRequired(String csvColumn, CsvContext context, CsvPreference preference) {
        if (1 == context.getLineNumber()) {
            /*
             * Case whene column names are written
             */
            return false;
        } else {
            return true;
        }
    }
}

使用自定义报价模式:

CsvPreference preference = new CsvPreference.Builder(CsvPreference.STANDARD_PREFERENCE).useQuoteMode(new AllExceptHeaderQuoteMode()).build());