Apache Camel中的JAXB编组 [英] JAXB marshalling in Apache Camel
本文介绍了Apache Camel中的JAXB编组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Apache camel的新手,需要执行一项任务,我需要将对象编组到xml文件中。
我使用下面的代码,但它不起作用。这里, foo.pojo
是包含JAXB注释类的包
I am new to Apache camel and need to perform a task where i need to marshal an object to xml file.
I am using the below code but it is not working. Here, foo.pojo
is package where JAXB annotated classes are present
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat("foo.pojo");
from("direct:start").marshal(jaxbDataFormat).to("file:C:/Users/Anand.Jain/Desktop/hello/abc.xml").end();
请帮忙。
推荐答案
选项1:配置上下文路径
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat("foo.pojo");
OptionFactory
或 jaxb.index
文件必须在给定的包中定义,如在这里。
OptionFactory
or jaxb.index
file must be defined in the given package as explained here.
选项2:将类配置为绑定
JAXBContext jaxbContext = JAXBContext.newInstance(MyAnnotatedClass.class);
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat(jaxbContext);
我更喜欢选项2。
这篇关于Apache Camel中的JAXB编组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文