I'm trying to use Apache Camel to parse XML to POJO and have problem with printing out the actual POJO. Instead I get regular XML as if no convertation not happening. When I pass for example Customer insted of Customers its working okay. Also printing Customers class to sout in bean warks perfectly.
MyRoute
@Autowired
private MyBean mb;
@Override
public void configure() throws Exception {
from("file:{{customer.path}}?noop=true")
.bean(mb)
.to("stream:out");
}
MyBean
@Handler
public Customers whatIsInBody(Customers body) {
return body;
}
POJO classes:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"customer"
})
@XmlRootElement(name = "customers")
public @Data
class Customers {
@XmlElement(required = true, nillable = true)
protected List<Customer> customer;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "customer", propOrder = {
"id",
"name",
"adress",
"countryCode",
"products"
})
public @Data
class Customer {
protected long id;
@XmlElement(required = true)
protected String name;
@XmlElement(required = true)
protected String adress;
@XmlElement(required = true)
protected String countryCode;
@XmlElement(required = true, nillable = true)
protected List<Product> products;
}
Output example:
<customers>
<customer>
<id>12345</id>
<name>str1234</name>
<adress>str1234</adress>
<countryCode>str1234</countryCode>
<products>
<id>12345</id>
<name>str1234</name>
</products>
</customer>
Desired output:
Customers(customer=[Customer(id=12345, name=str1234, adress=str1234, countryCode=str1234, products=[Product(id=12345, name=str1234)]),