I have a requirement to parse a CSV file with 1 header record (no Names), one to many detail records and one tail record as follows (input.csv) which needs to be converted into the output.json format.
I have used the below opencsv library to read the records into List of Array of string where each String array in the List represents 1 record.
There is also a bean mapping given in the opencsv but it doesn't have the facility to map the header record into a separate Bean, details records into array of separate beans and tail record into another separate bean.
http://opencsv.sourceforge.net/#reading_without_annotations_column_positions
So I am now stuck to produce the Json from the CSV with a Header, Multiple Detail and One Tail record.
Could someone please share some ideas to achieve this?
input.csv
1,,,
2,DC PIV REL11,D6,
2,DC PIV REL12,ADDED VIA SFTP12,
2,D6,ADDED VIA SFTP6,
3,123,END
output.json
{
"header": {
"type": "1",
"number": "",
"code": ""
},
{
"contents": {
"content": [
{
"type": "2",
"name": "DC PIV REL11",
"reference": "D6"
},
{
"type": "2",
"name": "DC PIV REL12",
"reference": "ADDED VIA SFTP12"
},
{
"type": "2",
"name": "D6",
"reference": "ADDED VIA SFTP6"
}
]
},
{
"tail": {
"type": "3",
"number": "123",
"code": "END"
}
}