Commons CSV
  1. Commons CSV
  2. CSV-92

Need a way to extract parsed headers, e.g. for use in formatting output

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0
    • Component/s: None
    • Labels:
      None

      Description

      Parsed header names are currently not accessible except as field key names, but these have to be known in advance.

      It would be useful to be able to have access to the header names:

      • to use in printing a header for a new CSV file. E.g. to read a CSV file and produce a new one with some changes made.
      • to write generic CSV applications

      The headers could be made available as a String array (in column number order) from the CSVParser class.
      The simplest would be to store the parsed (or provided) headers and return a clone of the array.

      If headers were not provided or requested, the method should probably return null rather than an empty array - to be decided.

        Activity

        Sebb created issue -
        Hide
        Vishal Bhavsar added a comment -

        Why not use CSVParser.getRecords()[0] to get the header array?

        Show
        Vishal Bhavsar added a comment - Why not use CSVParser.getRecords() [0] to get the header array?
        Sebb made changes -
        Field Original Value New Value
        Project Commons IO [ 12310477 ] Commons CSV [ 12313222 ]
        Key IO-317 CSV-92
        Workflow Default workflow, editable Closed status [ 12660258 ] jira [ 12672395 ]
        Hide
        Sven Maier added a comment -

        If I define a format with an empty header array

        CSVFormat myFormat = CSVFormat.BASE
        .withDelimiter('|')
        .withHeader();
        

        Then the CSVParser headerMapping map will be populated by the initializeHeader() method from the first line from the reader.

        As it is right now, this map can not be accessed from a client. It would be great if a client would have access to this map.

        Perhaps parser.getHeaderMapping() would be sufficient?

        Show
        Sven Maier added a comment - If I define a format with an empty header array CSVFormat myFormat = CSVFormat.BASE .withDelimiter('|') .withHeader(); Then the CSVParser headerMapping map will be populated by the initializeHeader() method from the first line from the reader. As it is right now, this map can not be accessed from a client. It would be great if a client would have access to this map. Perhaps parser.getHeaderMapping() would be sufficient?
        Hide
        Gary Gregory added a comment -

        Added getHeaderMap()

        Show
        Gary Gregory added a comment - Added getHeaderMap()
        Gary Gregory made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.0 [ 12320161 ]
        Resolution Fixed [ 1 ]
        Benedikt Ritter made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        166d 16h 24m 1 Gary Gregory 12/Sep/12 14:41
        Resolved Resolved Closed Closed
        701d 6h 24m 1 Benedikt Ritter 14/Aug/14 21:06

          People

          • Assignee:
            Unassigned
            Reporter:
            Sebb
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development