You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Marco Cuccato (Jira)" <ji...@apache.org> on 2022/05/27 10:55:00 UTC

[jira] [Updated] (CSV-297) setHeader() does not consider the separator while parse header row

     [ https://issues.apache.org/jira/browse/CSV-297?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Marco Cuccato updated CSV-297:
------------------------------
    Description: 
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.

  was:
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.


> 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
>            Priority: Major
>
> 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)