【问题标题】:Java Apache Camel XML JSON marshal creates At-SignsJava Apache Camel XML JSON 编组创建 At-Signs
【发布时间】:2016-09-07 09:25:54
【问题描述】:

我有两个问题: 1. 为什么在json文件中创建@-Signs? 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"
    }, 

【问题讨论】:

    标签: java json xml apache-camel


    【解决方案1】:

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

    Camel 使用的 JSon lib 项目已经没有那么活跃的开发了,所以你可能无法让他们添加一些功能来配置是否输出@

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-18
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      • 2019-07-02
      • 1970-01-01
      相关资源
      最近更新 更多