我有以下代码,这些代码是从 Apache Camel 网站获取的:
XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setEncoding("UTF-8");
xmlJsonFormat.setForceTopLevelObject(true);
xmlJsonFormat.setTrimSpaces(true);
xmlJsonFormat.setRootName("newRoot");
xmlJsonFormat.setSkipNamespaces(true);
xmlJsonFormat.setRemoveNamespacePrefixes(true);
xmlJsonFormat.setExpandableProperties(Arrays.asList("d", "e"));
// from XML to JSON
from("direct:marshal").marshal(xmlJsonFormat).to("mock:json"); // 1
在最后一行(标记为 1),我收到编译错误。我不明白 from
方法来自哪里;没有静态导入,我已经浏览了该网站上的示例和帖子。
我对 Camel 一无所知,并且想将其作为独立的实用程序类来运行,以进行简单的 xml -> json 转换。
任何人都可以帮助我理解我必须做什么才能使这个片段发挥作用。如果做不到这一点,有人知道一个简单的 xml 到 json 转换器吗?
最佳答案
开始使用 Camel 的一个好主意是浏览本入门指南
还可以阅读这篇文章,推荐在 5 分钟内很好地解释 Camel
然后你就会知道 from
来自 Camel 路由,并且你需要使用 RouteBuilder
类来使用它。
关于java - Apache Camel XmlJsonDataFormat XML 到 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29082608/