Hi,
I am a Java programmer and I am using the last version of common-csv library,
such as in my pom.xml I have this dependency:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.7</version>
</dependency>
This library is used in order to write a simple CSV file in a java application.
In particular use cases the column name headers of the csv file can be
duplicated.
I found an interesting property of the CSVFormat class that must be useful in
this case but, in every solution described below, the program terminates with
error such as:
Exception in thread "main" java.lang.IllegalArgumentException: The header
contains a duplicate entry: 'VV' in [CC, VV, VV]
at org.apache.commons.csv.CSVFormat.validate(CSVFormat.java:1676)
at org.apache.commons.csv.CSVFormat.<init>(CSVFormat.java:793)
at org.apache.commons.csv.CSVFormat.withHeader(CSVFormat.java:1986)
The code written is:
public static void main(String[] args){
CSVFormat formatCsv =
CSVFormat.DEFAULT.withAllowDuplicateHeaderNames().withHeader("CC","VV","VV");
System.out.println(formatCsv);
}
I tried 4 situations:
1)
CSVFormat formatCsv =
CSVFormat.DEFAULT.withAllowDuplicateHeaderNames().withHeader(headers);
2)
CSVFormat formatCsv =
CSVFormat.DEFAULT.withAllowDuplicateHeaderNames(true).withHeader(headers);
3)
CSVFormat formatCsv =
CSVFormat.DEFAULT.withHeader(headers).withAllowDuplicateHeaderNames();
4)
CSVFormat formatCsv =
CSVFormat.DEFAULT.withHeader(headers).withAllowDuplicateHeaderNames(true);
There is a bug for the withAllowDuplicateHeaderNames property?
Thanks for your answer.
I think that is a Jira Open:
https://jira.apache.org/jira/browse/CSV-236
Regards.
macsharker6
Sent with [ProtonMail](https://protonmail.com) Secure Email.