How to read same more than one column having same name in Java
Description: I am converting CSV to JSON by reading csv schema and successful into it, but the problem is that the CSV file contains two column having same name, and it is overriding the second column value into first one and not showing the second column in json.
My requirement is to read both column values into json and pass on, as The code block is below, I browsed to find a work around, yet not successful! My Application is written in java.
Code
public List<Map<?, ?>> convert(String file) throws Exception {
File input = new File(file);
try {
CsvSchema csv = CsvSchema.emptySchema().withHeader();
CsvMapper csvMapper = new CsvMapper();
MappingIterator<Map<?, ?>> mappingIterator = csvMapper.reader().forType(Map.class).with(csv).readValues(input);
List<Map<?, ?>> list = mappingIterator.readAll();
return list;
} catch(Exception e) {
e.printStackTrace();
return null;
}
}
JSON I want
[
{
UserName=DasKhatri, Pass=777, Name=Guru, FamilyName=Khatri, ShortName=GK, UserName=GuruKhatri, Pass=111
}
]
JSON I am Getting
[
{
UserName=GuruKhatri, Pass=111, Name=Guru, FamilyName=Khatri, ShortName=GK
}
]