相关文章推荐

Hello,

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.

Discussion

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

column="value"
column={"value"} 
column={"value", "value2"}

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

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:

@CsvBindByName(column="column1", profile="profile1")
@CsvBindByName(column="column2", profile="profile2")
private String field;

and during building reader or writer user can tell which profile/strategy is used:

.withProfileName("profile1")

What do you think?

 
推荐文章