I want to convert multiple xml object to json object in apache camel. But I am just able to convert single object. With reference to below and attached code, I have tried some methods
- Make ArrayList in the Employee class
- ListJacksonDataFormat in XMLToJSONRoute class But neither work.
Could someone point out what I am doing wrong?
Employee.class
@DataField(pos = 1)
private int empId;
@DataField(pos = 2)
private String empName;
@DataField(pos = 3)
private int sal;
// XMLElement
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
// XMLElement
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
Main class
XMLToJSONRoute routeBuilder = new XMLToJSONRoute();
CamelContext ctx = new DefaultCamelContext();
try {
ctx.addRoutes(routeBuilder);
ctx.start();
Thread.sleep(5 * 60 * 1000);
ctx.stop();
XMLtoJSON route
@Override
public void configure() throws Exception {
//JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class);
//Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
JaxbDataFormat xmlDataFormat = new JaxbDataFormat();
//1. XML Data Format
JAXBContext con = JAXBContext.newInstance(Employee.class);
xmlDataFormat.setContext(con);
JacksonDataFormat jsonDataFormat = new JacksonDataFormat(Employee.class);
// 1. JSON Data Format
//ListJacksonDataFormat jsonDataFormat2 = new ListJacksonDataFormat(Employee.class); // 1. JSON Data Format
from("file:C:/inputFolder/.camel/xml?noop=true")
.unmarshal(xmlDataFormat)
//.marshal().xstream()
//Unmarshaled debug part
.process(new Processor(){
//Unmarshaled debug part
.marshal(jsonDataFormat)
.to("file:C:/outputFolder/json").
// Marshalled output
process(new Processor(){
public void process(Exchange exchange) throws Exception {
;}
}