如何解决在 Apache Camel 中使用 JaxbDataFormat 进行编组
在我在互联网上看到的所有示例中,都需要调用“setContext”。但是这个函数在 JaxbDataFormat 中不存在。从 xml 转换为 Json 的任何想法或替代方法
// XML Data Format
JaxbDataFormat xmlDataFormat = new JaxbDataFormat();
JAXBContext con = JAXBContext.newInstance(Employee.class);
**xmlDataFormat.setContext(con);**
// JSON Data Format
JacksonDataFormat jsonDataFormat = new JacksonDataFormat(Employee.class);
from("file:C:/inputFolder").doTry().unmarshal(xmlDataFormat).
process(new MyProcessor()).marshal(jsonDataFormat).
to("jms:queue:javainuse").doCatch(Exception.class).process(new Processor() {
public void process(Exchange exchange) throws Exception {
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,Exception.class);
System.out.println(cause);
}
});
谢谢!
解决方法
你找不到这个函数,因为你没有导入这个包:
import org.apache.camel.converter.jaxb.JaxbDataFormat;
或者因为您没有在 pom.xml 中添加此依赖项:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb</artifactId>
<version>${camel-version}</version>
</dependency>
您可以在此处查看我的参考档案https://metiago.github.io/dev/2017/02/12/java-apache-camel-xml.html?query=camel以获得更好的示例。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。