Dave Moten created CSV-239:
------------------------------

             Summary: Cannot get headers in column order from CSVRecord
                 Key: CSV-239
                 URL: https://issues.apache.org/jira/browse/CSV-239
             Project: Commons CSV
          Issue Type: Improvement
          Components: Parser
    Affects Versions: 1.6
            Reporter: Dave Moten


I have a use case where I read many lines from an arbitrary csv file with a 
given CSVFormat as List<CSVRecord>, transform that list and then want to write 
the transformed list to another file. 

When I specify the format as CSVFormat.DEFAULT.withFirstRecordAsHeader() the 
headers from the first line are available in the CSVRecord object via the 
CSVRecord.toMap object but their column positions are not (the iteration of the 
returned map does not reflect column order). Consequently I cannot write a 
header line in the correct order to the output csv file (which I do when the 
first CSVRecord is to be written).

Another option would be to be to ensure that the CSVPrinter object writes the 
header on the first call to CSVPrinter.printRecord. 

My preference at minimum is that the headers with column order are available 
from CSVRecord. The addition of a method `getHeaders` returning a 
`List<String>` would do the job. I'm happy to submit a PR if desired.

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to