[英]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. 我正在使用Jackson CSV生成CSV文件,但我希望到处都有报价。 I couldn't find any information on the ApiDoc . 我在ApiDoc上找不到任何信息。
CSV writer CSV编写器
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 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. 谢谢。
Ok I finally found it by looking at the ApiDoc and searching with Google on how I could put it all together. 好的,我终于通过查看ApiDoc并在Google上搜索如何将它们组合在一起找到了它。 Here the solution to enabling the feature that I wanted: 这里是启用我想要的功能的解决方案:
mapper.configure(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS, true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.