我有一个简单的XML文件,需要使用camel-xmljson JAR将其转换为JSON。我从以下几个方面开始骆驼上下文:
Main main = new Main();
main.addRouteBuilder(new ConvertXmlToJson());
main.enableHangupSupport();
main.run();我的配置方法如下所示:
@Override
public void configure() throws Exception {
XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setForceTopLevelObject(true);
// from XML to JSON
//#1
from("direct:marshal").marshal(xmlJsonFormat).to("mock:json");
//#2
//from("file:resources/SimpleFile.xml").marshal(xmlJsonFormat).to("file:resources/JsonOutput.txt");
}现在,我无法理解应该在哪里传递xml对象?第二条看起来对吗?当我处决他们中的任何一个时,什么都不会发生。
在控制台而不是文件上打印转换后的JSON也可以。
提前谢谢你的帮助。
发布于 2014-08-01 11:49:36
只要把你的路线改为:
from("file:resource/inbox").marshal(xmlJsonFormat).to("file:resource/outbox");然后将SimpleFile.xml复制到资源/收件箱中,运行应用程序,您将在资源/发件箱中获得JSON
https://stackoverflow.com/questions/25060938
复制相似问题