Uploaded image for project: 'Commons CSV'
  1. Commons CSV
  2. CSV-297

setHeader() does not consider the separator while parse header row

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.9.0
    • None
    • Parser
    • None

    Description

      If you try to parse a file like this:

      name$value
      a$1
      b$0
      c$3

      with a CSVFormat defined like this:

      CSVFormat.DEFAULT.builder()
                      .setRecordSeparator("$")
                      .setHeader()
                      .build(); 
      

      and then try to retrieve a field by name with:

      record.get("name")

      i get the following error:

       

      java.lang.IllegalArgumentException: Mapping for name not found, expected one of [name$value]
          at org.apache.commons.csv.CSVRecord.get(CSVRecord.java:121)
       
      

      Looks like the parser does not consider the separator when auto detects headers.

      If I modify the source file using comma as separator and 

      format.setRecordSeparator(",")

       it works.

      Attachments

        Activity

          People

            Unassigned Unassigned
            StanGoodspeed Marco Cuccato
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: