I am creating an endpoint that, gets parameters:
- a CSV file
- name of a class (that I will use to create an instance of)
In mapping I am using CommonsCSV library.
Although I am getting CSVRecord
I couldn't map it to an instance of the class I got as a parameter.
Example: as A parameter I got:-
- CSV
id | firstName | lastName |
---|---|---|
1 | John | Rodriguez |
2 | Michael | Hernandez |
3 | David | Smith |
className
'employee'
// employee class
Class<?> classType = Class.forName(className);
// CSV file records
List<CSVRecord> records = csvParser.getRecords();
for (int i = 0; i < records.size(); i++) {
CSVRecord record = records.get(i);
// I want to get an instance of employee to save it to database like this
{
"id" : 1,
"firstName" : "John",
"lastName" : "Rodriguez"
}
}
Thanks in advance!