Apache Camel 中的 JAXB 编组 [英] JAXB marshalling in Apache Camel

查看:29
本文介绍了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");

OptionFactoryjaxb.in​​dex 文件必须在给定的包中定义,如此处.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆