Marco Cuccato created CSV-297:
---------------------------------

             Summary: setHeader() does not consider the separator while parse 
header row
                 Key: CSV-297
                 URL: https://issues.apache.org/jira/browse/CSV-297
             Project: Commons CSV
          Issue Type: Bug
          Components: Parser
    Affects Versions: 1.9.0
            Reporter: Marco Cuccato


If you try to parse a file like this:
{code:java}
name$value
a$1
b$0
c$3{code}
with a CSVFormat defined like this:

 
{code:java}
CSVFormat.DEFAULT.builder()
                .setRecordSeparator("$")
                .setHeader()
                .build(); 
{code}
and then try to retrieve a field by name with:
{code:java}
record.get("name"){code}
i get the following error:

 
{code:java}
java.lang.IllegalArgumentException: Mapping for name not found, expected one of 
[name$value]
    at org.apache.commons.csv.CSVRecord.get(CSVRecord.java:121)
 
{code}
Looks like the parser does not consider the separator when auto detects headers.

If I modify the source file using comma as separator and 
{code:java}
format.setRecordSeparator(","){code}
 it works.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to