Would it be possible to change "column" from String to String[] in the CsvBindByName annotation?
During processing first matching column name from the list would bind to POJO field.
For my use case I gather data from multiple CSV files with different header names. Currently I have to map them into multiple beans. The data has the same bussines meaning under different headers depending on source.
Last edit: Mark Green 2020-10-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What we both forgot about was writing. If we have a bean like this with multiple options for a header name and the user wants to write the bean out to a CSV file, which of the possible header names should opencsv choose?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
At first I hated your profile idea. Then I thought about it a few minutes, and now I'm in love with it. Profiles would be a wonderful feature. I suspect many users would find a use for them, and they're far more general than your original suggestion. I think we have a winner!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Without breaking backward compatibility, which we will not consider until 6.0? No. I don't think I see a way of doing this.
I would be interested in your use case, though. It's an odd request, and a bit intriguing.
To be honest I don't think it would break backward compatibility as you can define String[] as
For my use case I gather data from multiple CSV files with different header names. Currently I have to map them into multiple beans. The data has the same bussines meaning under different headers depending on source.
Last edit: Mark Green 2020-10-25
Then I will cogitate on it for a while.
What we both forgot about was writing. If we have a bean like this with multiple options for a header name and the user wants to write the bean out to a CSV file, which of the possible header names should opencsv choose?
I would use the first one for simplicity.
Another approach can be with repeating annotations(since Java 8 is minimum supported version) and adding something like profiles/strategies:
and during building reader or writer user can tell which profile/strategy is used:
What do you think?
At first I hated your profile idea. Then I thought about it a few minutes, and now I'm in love with it. Profiles would be a wonderful feature. I suspect many users would find a use for them, and they're far more general than your original suggestion. I think we have a winner!
Yeah, they would allow different configurations for other goodies. I'm glad you like it :)
The profile feature will be released with the next version of opencsv.
5.4 was released a couple of days ago. Sorry to leave you hanging like that.