Maurice
Maurice

Reputation: 2259

Generating a CSV with Jackson, no Quoted Char

I am using Jackson CSV to generate a CSV file, but I want to have the quote everywhere. I couldn't find any information on the ApiDoc.

CSV writer

CsvMapper mapper = new CsvMapper();
//objects is a list
CsvSchema schema = mapper.schemaFor(objects).withHeader();
schema = schema.withQuoteChar('\"');

Expected Output

"name","value"
"fieldName1","5"
"fieldName2","2"
"fieldName3","5"

Actual Output

name,value
fieldName1,5
fieldName2,2
fieldName3,5

pom.xml

    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-csv</artifactId>
        <version>2.6.3</version>
    </dependency>

If it's not possible with Jackson I am open to try another library. Thanks.

Upvotes: 6

Views: 8245

Answers (1)

Maurice
Maurice

Reputation: 2259

Ok I finally found it by looking at the ApiDoc and searching with Google on how I could put it all together. Here the solution to enabling the feature that I wanted:

 mapper.configure(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS, true);

Upvotes: 17

Related Questions