Skip to content

Add an header line assertion/check #151

Description

@dylanbehetre

Is your feature request related to a problem? Please describe.

I want to assert the CSV file header content when I working with NamedCsvRecord.

There is no solution today to assert the header line of the csv file without checking all records.

Describe the solution you'd like

final var handler = NamedCsvRecordHandler.builder()
                               .expectedHeader("header A", "header B") // proposal
                               .build();
try (CsvReader<NamedCsvRecord> csvReader = CsvReader.builder()
                                                                                                      .build(handler, file.getInputStream())) {
    return csvReader.stream()
			.map(this.csvRecordMapper::map)
			.collect(Collectors.toCollection(LinkedHashSet::new));
}

So add an expectedHeaders List in NamedCsvRecordHandler and use it to validate headers.

Goal alignment

Seems to be aligned : simplify headers verifications without check on all lines without impact performances.

I can do a PR if your are aligned @osiegmar.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions