I have the following Java class:
public class Pessoa {
private String employee_name;
private String user_id;
private String domain;
private String email;
private String role;
@Override
public String toString() {
return "Pessoa [employee_name=" + employee_name + ", user_id=" + user_id + ", domain=" + domain + ", email="
+ email + ", role=" + role + "]";
}
// Gets e Sets omitidos para ficar menor
}
The following CSV file:
employee_name,user_id,domain,email,role
BurtonMStephenson,BMS0001,dtaa.com,[email protected],Security
Keelie M Goodwin,KMG0002,dtaa.com,[email protected],Engineer
Dara O Craig,DOC0003,dtaa.com,[email protected],VP
I have the class responsible for reading the CSV file and playing on objects of type Pessoa
:
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.bean.CsvToBean;
import com.opencsv.bean.CsvToBeanBuilder;
public class LerLinhasOpenCsv {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Reader reader = Files.newBufferedReader(Paths.get("LDAP_head.csv"));
CsvToBean<Pessoa> csvToBean = new CsvToBeanBuilder(reader)
.withType(Pessoa.class).build();
List<Pessoa> pessoas = csvToBean.parse();
for (Pessoa pessoa : pessoas)
System.out.println(pessoa.toString());
}
}
But when I print everything null
appears:
Pessoa [employee_name=null, user_id=null, domain=null, email=null, role=null]
Pessoa [employee_name=null, user_id=null, domain=null, email=null, role=null]
Pessoa [employee_name=null, user_id=null, domain=null, email=null, role=null]
Pessoa [employee_name=null, user_id=null, domain=null, email=null, role=null]
Pessoa [employee_name=null, user_id=null, domain=null, email=null, role=null]