I have this input .csv file(here just a sample - there are 1.500.000 line)
OBJECT_ID¦TYPE¦NAME¦PARENT_ID¦MANUFACTURER¦POSITION_CODE¦MAINTENANCE_STATUS¦PHYSICAL_STATUS
9143101068113202824¦Card¦H603CSRI - 6¦9143101069013360101¦Huawei Technologies¦74EX.G010.R13.031 (H603).006¦Not on Maintenance¦In Service
9143101068113202825¦Card¦H603CSRI - 7¦9143101069013360101¦Huawei Technologies¦74EX.G010.R13.031 (H603).007¦Not on Maintenance¦In Service
I've created a model class called Card
public class Card {
@CsvBindByName(column = "OBJECT_ID")
private String object_id;
@CsvBindByName(column = "TYPE")
private String type;
@CsvBindByName(column = "NAME")
private String name;
@CsvBindByName(column = "PARENT_ID")
private String parent_id;
@CsvBindByName(column = "MANUFACTURER")
private String manufacturer;
@CsvBindByName(column = "POSITION_CODE")
private String position_code;
@CsvBindByName(column = "MAINTENANCE_STATUS")
private String maintenance_status;
@CsvBindByName(column = "PHYSICAL_STATUS")
private String physical_status;
public Card() { }
public Card(String object_id, String type, String name, String parent_id, String manufacturer, String position_code, String maintenance_status, String physical_status) {
this.object_id = object_id;
this.type = type;
this.name = name;
this.parent_id = parent_id;
this.manufacturer = manufacturer;
this.position_code = position_code;
this.maintenance_status = maintenance_status;
this.physical_status = physical_status;
}
public String getObject_id() {
return object_id;
}
public void setObject_id(String object_id) {
this.object_id = object_id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getParent_id() {
return parent_id;
}
public void setParent_id(String parent_id) {
this.parent_id = parent_id;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getPosition_code() {
return position_code;
}
public void setPosition_code(String position_code) {
this.position_code = position_code;
}
public String getMaintenance_status() {
return maintenance_status;
}
public void setMaintenance_status(String maintenance_status) {
this.maintenance_status = maintenance_status;
}
public String getPhysical_status() {
return physical_status;
}
public void setPhysical_status(String physical_status) {
this.physical_status = physical_status;
}
}
And I have this method that should load all the csv content into the cards List
and then put the data into a Map
public static Map<String, Card> getAllCards(String fileLocation) {
log.logInfo("getAllCards started!");
long totalTime = System.currentTimeMillis();
Map<String, Card> map = new HashMap<>();
try (
Reader reader = Files.newBufferedReader(Paths.get(fileLocation))
) {
CsvToBean<Card> csvToBean = new CsvToBeanBuilder(reader)
.withSeparator('¦')
.withType(Card.class)
.withIgnoreLeadingWhiteSpace(true)
.build();
List<Card> cards = csvToBean.parse();
System.out.println(cards.size());//1.535.232
for(Card card: cards) {
Card cardObj = new Card(card.getObject_id(),card.getType(),card.getName(), card.getParent_id(),
card.getManufacturer(), card.getPosition_code(), card.getMaintenance_status(),card.getPhysical_status());
map.put(card.getObject_id(), cardObj);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(map.get("OBJECT_ID"));//null
System.out.println(map.size());//1 as it inserts only one null key
log.logInfo("getAllCards completed in " + ((double) (System.currentTimeMillis() - totalTime) / 1000) + " sec.");
return map;
}
The problem is that the cards List contains a list of objects that have all null values. The size is correct so it is reading the csv file but is not populating with data. Any idea on what is happening?