I am using JSEFA to serialize my java object to into single row in CSV using JSEFA. I have arround 46 fields in one single class ,
But now the problem is i want to split this class into different sub classes which holds information,One class contains fields of CSV for first 23 positions and next class contains remaining position. When i tried approach of Prefix it is inserting data into two different rows but i need all data of two classes into a single row can some body suggest best approach using JSEFA or any other .
First class contains first two fields:
@CsvDataType(defaultPrefix = "1")
public class TestClass1 implements Serializable {
private static final long serialVersionUID = 371968159365574089L;
@CsvField(pos = 1)
private int id;
@CsvField(pos = 2)
private String Name;
public int getId() {
return this.id;
}
public void setId(final int id) {
this.id = id;
}
public String getName() {
return this.Name;
}
public void setName(final String name) {
this.Name = name;
}
}
Sub Class 2 which contains remaining two fields:
@CsvDataType(defaultPrefix = "2")
public class TestClass2 implements Serializable {
private static final long serialVersionUID = 371968159365574089L;
@CsvField(pos = 3)
private int orderno;
@CsvField(pos = 4)
private String orderName;
public int getOrderno() {
return this.orderno;
}
public void setOrderno(final int orderno) {
this.orderno = orderno;
}
public String getOrderName() {
return orderName;
}
public void setOrderName(String orderName) {
this.orderName = orderName;
}
}
main method for combining:
public static void main(final String[] args) {
final File file = new File("/home/chandra/Documents/dataExcelFiles/final.csv");
file.getParentFile().mkdirs();
Serializer serializer = CsvIOFactory.createFactory(TestClass.class, TestClass2.class).createSerializer();
TestClass prod1 = new TestClass();
prod1.setId(1);
prod1.setName("HTC");
TestClass2 prod2 = new TestClass2();
prod2.setOrderno(512);
prod2.setOrderName("HTC500");
try {
serializer.open(new FileWriter(file));
serializer.write(prod1);
serializer.write(prod2);
serializer.close(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Using this approach out put is like this :
- 1 1 HTC
- 2 512 HTC500
but i need out put every thing in one row like this:
- 1 HTC 512 HTC500
Thanks, Chandra