Java Apache Camel XML JSON 编码创建 At-Signs

标签 java json xml apache-camel

我有两个问题: 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"
    }, 

Eclipse Console

最佳答案

这就是 XmlJson 开箱即用的工作方式,以区分值是 XML 属性还是 XML 值。

Camel 使用的 JSon lib 项目不再那么活跃开发,因此您可能无法让他们添加一些功能来配置是否输出 @

关于Java Apache Camel XML JSON 编码创建 At-Signs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39366081/

相关文章:

java - Jackson:反序列化包含列表的泛型类型

java - 最喜欢的开源 Google App Engine 应用(Java 或 Python)

java - jsp中的下载链接不起作用

javascript - Node-Webkit 无法打开文件

java - 没有时区信息的 XMLBeans 日期

java - TestNG - java.net.SocketException

ios - 当预期类型可能不同时,如何安全地处理 JSON 数据?

json - 错误 : the type of this value must be known in this context (Rust)/serde_json Value

c# - 用于搜索节点后代的 Xpath

c# - Linq to object 的性能问题需要更多时间