-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support parsing CSV with header regardless of unknown columns #286
Comments
Reorder the columns:
or skip adding columns explicitly when using setUseHeader(true)
|
But the use case expects the columns name and age in given order and should fail otherwise. jackson-dataformats-text/csv/src/main/java/com/fasterxml/jackson/dataformat/csv/CsvParser.java Line 787 in 8107723
and can be considered as a bug.
But then |
Same issue was encountered with jackson-dataformat-csv 2.13.4, trying to parse a csv file(>100 columns) to a Java entity(10 attributes). I have tried to use
But I have found that the values in the unknown columns are parsed to the next column, messed up data in the DB. As @bjmi mentioned, IGNORE_UNKNOWN_PROPERTIES will likely solve my problem
|
I can get it to work if when reading I use a schema .withHeader() and .withColumnReordering(). FAIL_ON_UNKNOWN_PROPERTIES is disabled for me, but I didn't test if it's necessary. So in the end I am using two different schemas: for writing without column reordering and for reading with column reordering. |
When reading given CSV with jackson-dataformat-csv 2.11.4
using following snippet
a CsvMappingException is thrown (Too many entries: expected at most 2) because the column weight is not known to CsvSchema.
csvMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
still leads to the same CsvMappingException.Thus please introduce a new CsvParser feature e.g.
IGNORE_UNKNOWN_COLUMNS
(disabled by default) that allows reading CSV regardless of unknown columns.The text was updated successfully, but these errors were encountered: