XML을 POJO로 구문 분석하는 데 Apache Camel을 사용하려고하는데 실제 POJO를 인쇄하는 데 문제가 있습니다. 대신 변환이 일어나지 않는 것처럼 일반 XML을 얻습니다. 예를 들어 고객의 고객 인스 트루먼트를 통과하면 정상적으로 작동합니다. 또한 콩 클래스에서 sout으로 Customers 클래스를 인쇄하는 것도 완벽하게 짖는다.Camel은 Java DSL 경로에서 POJO를 인쇄하지 않습니다.
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 클래스 :
@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;
}
출력 예 :
<customers>
<customer>
<id>12345</id>
<name>str1234</name>
<adress>str1234</adress>
<countryCode>str1234</countryCode>
<products>
<id>12345</id>
<name>str1234</name>
</products>
</customer>
원하는 출력 : 당신은 클래스 패스에 다음 POJO를 낙타 JAXB 한
Customers(customer=[Customer(id=12345, name=str1234, adress=str1234, countryCode=str1234, products=[Product(id=12345, name=str1234)]),
당신은 낙타의 데이터 형식을 보았 느냐? Jackson XML 및 자동 언 마샬링을 수행 할 수있는 데이터 형식이 내장되어 있습니다. http://camel.apache.org/jackson-xml.html –
@SoucianceEqdamRashti 별도의 메인에서 jaxb를 사용해 보았습니다. jaxb가 JAXBContext 인 jc = JAXBContext 인 .unmarshal (jaxb)을 추가하려고하면 괜찮습니다. .newInstance (Customers.class); DataFormat jaxb = 새로운 JaxbDataFormat (jc); 하지만 경로에 추가하면 아무 일도 일어나지 않습니다 ... – Eugene
당신이 여기에 설명 된 것을 좋아하니? https://stackoverflow.com/questions/26800182/jaxb-marshalling-in-apache-camel –