I have a requirement to,
- combine two CSV columns into one bean attribute.
- Perform a simple mathematical operation on a column value and map to bean attribute.
Wondering if something like this is possible using OpenCSV annotations.
Input CSV
User ID, First Name, Last Name, Worked Minutes
1234,Jon,Snow,60
1235,Rob,Stark,30
Bean
public class Employee {
@CsvBindByName(column = "Employee ID")
private String userId;
//this should be "First Name, Last Name"
private String employeeName;
//this should be Worked Minutes/60
private String workedHours;
//getters and setters
}
The only way I have managed to do this is by mapping the columns as it is to separate attributes (userId
, firstName
, lastName
, workedMinutes
) and then modifying the employeeName
and workedHours
getter methods, but I feel like there should be a better way to do this.