我有两个问题: 1. 为什么在 json 文件中创建@符号? 2. 为什么在 xml-json 编码之后进程仍在运行? (查看我的 EclipseConsole-Screenshot。每次运行我都必须终止该进程。)
MyRouteBuilder配置方法
public void configure() throws Exception{
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("timer:timer1?period=100&repeatCount=1")
.to("https://...foo")
.marshal(xmlJsonFormat)
.to("file:target/messages/others?noop=true&fileName=message.json");
}
输入 xml - 示例段
<hotel name="Hotel foo" cat="5" mh="xxx"/>
<date from="2016-10-16" to="2016-10-18"/>
输出 json - 示例段
"hotel" : {
"@name" : "Hotel foo",
"@cat" : "5",
"@mh" : "xxx"
},
"date" : {
"@from" : "2016-10-18",
"@to" : "2016-10-19"
},
最佳答案
这就是 XmlJson 开箱即用的工作方式,以区分值是 XML 属性还是 XML 值。
Camel 使用的 JSon lib 项目不再那么活跃开发,因此您可能无法让他们添加一些功能来配置是否输出 @
。
关于Java Apache Camel XML JSON 编码创建 At-Signs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39366081/