I have to write a list of obects to a json file using beanIO. whenever i tried i am getting only the first object getting written to the file as below.
{"employeeDetails":[{"recordType":"I","empId":"100","empName":"Name1"}]}
actual result should be as below:
{"employeeDetails":[{"recordType":"I","empId":"100","empName":"Name1"},{"recordType":"I","empId":"101","empName":"Name2"}]}
using pojo as below:
@Record
public class Employee{
@Field(minOccurs=0)
private String recordType;
@Field(minOccurs=0)
private String empId;
@Field(minOccurs=0)
private String empName;
// getters and setters
}
@Record
public class Department{
@Segment(minOccurs=0, collection=List.class)
private List<Employee> employeeDetails;
//getters and setters
}
this is what my impl class does,
StreamFactory streamFactory=StreamFactory.newInstance();
streamFactory.loadResource(beanIoPath + beanIoMappingFileName);
Writer outJson = new BufferedWriter(new FileWriter(new File(absPath+fileName)));
BeanWriter jsonBeanWriter = streamFactory.createWriter(mapper, outJson);
Department dpt = //fetch from db;
jsonBeanWriter.write(dpt);
Please suggest what should be added more, how to achieve writing list of objects into a json file using BeanIO.
Thank you..