Apache Camel 中的 JAXB 编组

Ana*_*and 1 jaxb marshalling apache-camel

我是 Apache camel 的新手,需要执行一项需要将​​对象编组到 XML 文件的任务。我正在使用下面的代码,但它不起作用。这里foo.pojo是存在 JAXB 注释类的包

JaxbDataFormat jaxbDataFormat =  new JaxbDataFormat("foo.pojo");
from("direct:start").marshal(jaxbDataFormat).to("file:C:/Users/Anand.Jain/Desktop/hello/abc.xml").end();
Run Code Online (Sandbox Code Playgroud)

Pet*_*ler 5

选项 1:配置上下文路径

JaxbDataFormat jaxbDataFormat =  new JaxbDataFormat("foo.pojo");
Run Code Online (Sandbox Code Playgroud)

OptionFactoryjaxb.index文件必须在给定的包被定义为解释在这里

选项 2:配置要绑定的类

JAXBContext jaxbContext = JAXBContext.newInstance(MyAnnotatedClass.class);
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat(jaxbContext);
Run Code Online (Sandbox Code Playgroud)

我更喜欢选项 2。