dominikschlosser / super-csv-declarative

Unofficial declarative extension to super-csv
Apache License 2.0
2 stars 1 forks source link

Feature: ignore undefined columns #3

Closed thomas-mc-work closed 8 years ago

thomas-mc-work commented 8 years ago

If I decide to use the annotation @CsvField(order = n) then it would come in handy have every other undefined column ignored (all column indexes except n). Now when I omit the definition of any column then I get this exception:

java.lang.IllegalArgumentException: the number of fields in the bean and the number of columns read should be the same size (nameMapping length = 11, columns = 12)

I would suggest to rename the annotation property order for @CsvField to index to avoid confusion.

Besides that: Thanks a lot for your great idea and effort!

dominikschlosser commented 8 years ago

Hi Thomas,

thank you for your feedback! You are right in that the design is not consistent right now. One would think that @CsvField is used to mark all csv-column-fields but it's sole purpose right now is to define the column order in cases where you can not rely on the JVM returning fields in the implicitly defined order. I have designed this library primarily with my own use case in mind, where this assumption can be safely made since the Oracle JVM is set. This is of course an edge case and should therefore not be the primarily supported way of using the library.

I will change this in the near future. Until then: You can use @CsvTransient to explicitly ignore fields.

Renaming order to index is a good idea, too.

thomas-mc-work commented 8 years ago

If index is going to be the only value for the CsvField annnotation then you could simplify the notation by renaming the method to value(). This enables to define the annotation like this:

@CsvField(4)
thomas-mc-work commented 8 years ago

Until then: You can use @CsvTransient to explicitly ignore fields.

Maybe my description was misleading: I would like to ignore all columns in the file that are not explicitely addressed via the annotation. So I could read only one column out of a file with 20 column by defining only the one column.