gpt4 book ai didi

Apache Camel 中的 JAXB 编码

转载 作者:行者123 更新时间:2023-12-01 22:34:22 25 4
gpt4 key购买 nike

我是 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();

最佳答案

选项 1:配置上下文路径

JaxbDataFormat jaxbDataFormat =  new JaxbDataFormat("foo.pojo");

OptionFactoryjaxb.in​​dex 文件必须在给定包中定义,如 here 所述.

选项 2:配置要绑定(bind)的类

JAXBContext jaxbContext = JAXBContext.newInstance(MyAnnotatedClass.class);
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat(jaxbContext);

我更喜欢选项 2。

关于Apache Camel 中的 JAXB 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26800182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com