dominikschlosser / super-csv-declarative

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

possible Bug: No default processor selected when using @Optional #4

Closed thomas-mc-work closed 8 years ago

thomas-mc-work commented 8 years ago

When my field has the annotation @Optional then no corresponding processor for the data type is selected. E.g. ParseInt is missing for all intand Integer fields. I would expect to have it created by the library, except when override it manually.

My workaround is to define the Processor manually:

@CsvField(order = 7)
@Optional(order = 0)
@ParseChar(order = 1)
private Character myValue;
dominikschlosser commented 8 years ago

That is not a bug but could be a possible improvement. It is implemented this way on purpose since one might use another processor than the default ones to do the conversion. The only situation where ParseXXX-annotations are added automatically is when there is no processor-annotation at all. In all other cases we would need to check the return type of the last CellProcessor which can not be done right now because of type-erasure and thus would require major changes.

Two possible solutions:

Suggestions welcome.

thomas-mc-work commented 8 years ago

What about declaring a marker interface for data type conversion processors (like ParseInt). If there is none of them defined then automatically select a default one derived by the variable type (via BeanCellProcessorExtractor::mapFieldToDefaultProcessor()).

dominikschlosser commented 8 years ago

Changing processors is out of scope of this project since it is merely an addon to SuperCSV. But your suggestion is great anyway because there are already marker interfaces for primitive type conversions in the framework as far as i remember :-)

thomas-mc-work commented 8 years ago

Alright, sounds good. Otherwise you could not mark the processors (which makes sense that this is out of scope) but maybe the annotations, but your approach sounds more reasonable.