Missing columns from header line (compare to `CsvSchema`) not detected when reordering columns (add `CsvParser.Feature.FAIL_ON_MISSING_HEADER_COLUMNS`)
See original GitHub issueWhen reading given CSV with jackson-dataformat-csv 2.11.4
name
Roger
Chris
using following snippet
CsvMapper csvMapper = new CsvMapper();
csvMapper.configure(CsvParser.Feature.FAIL_ON_MISSING_COLUMNS, true);
CsvSchema csvSchema = CsvSchema.builder().setUseHeader(true).setReorderColumns(true)
.addColumn("name").addColumn("age").build();
List<Person> persons = csvMapper
.readerFor(Person.class)
.with(csvSchema)
.<Person> readValues(csv)
.readAll();
...
class Person {
public String name;
public int age;
}
doesn’t throw a CsvMappingException
although age
column is missing in CSV.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Jackson CSV missing columns - java - Stack Overflow
I know this is an old thread, but as I run into the same question myself, let me share the solution : csvMapper.configure(CsvParser.Feature....
Read more >CsvParser.Feature (Jackson-dataformat-CSV 2.12.3 API)
Feature that allows ignoring of unmappable "extra" columns; that is, values for columns that appear after columns for which types are defined.
Read more >How to Read or Parse CSV files with Header in Java ... - Java67
How to parse a CSV file with column header in Java using Jackson ... CSV to Java objects while CsvSchema defines Schema as...
Read more >Reading CSV with Jackson - cowtowncoder
It may or may not contain logical names for columns (more on this bit later). Since Jackson API was designed to work with...
Read more >com.fasterxml.jackson.dataformat.csv.CsvSchema.builder java ...
Accessor for creating a "default" CSV schema instance, with following * settings: *<ul> * <li>Does NOT use header line * </li> * <li>Uses...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok: changed the behavior to optionally throw an exception if column headers are missing (compared to registered
CsvSchema
), controller by newCsvParser.Feature.FAIL_ON_MISSING_HEADER_COLUMNS
which defaults to
true
(that is, by default this problem is reported).Will be in 2.14.0 release
I.e., should there be something like this?