【发布时间】:2014-12-05 15:02:29
【问题描述】:
以下代码行可以正常工作
.setBody(constant("{\"filter\":{\"bool\":{\"must\":{\"type\":{\"value\":\"channels\"}},\"should\":{},\"must_not\":{\"missing\":{\"field\":\"sourceId\",\"existence\":true,\"null_value\":true}}}},\"fields\":[\"sourceId\",\"callSign\",\"name\"],\"from\":0,\"size\":10000}"))
但是,当如下所示在属性文件中指定 JSON 值时,如果按如下方式调用,则会失败:
.setBody(simple("{{es.stations}}"))
es.stations 设置如下图
es.stations={"filter"\:{"bool"\:{"must"\:{"type"\:{"value"\:"channels"}},"should"\:{},"must_not"\:{"missing"\:{"field"\:"sourceId","existence"\:true,"null_value"\:true}}}},"fields"\:["sourceId","callSign","name"],"from"\:0,"size"\:10000}
抛出的异常如下:
Caused by: java.lang.IllegalArgumentException: Missing {{ from the text: {"filter":{"bool":{"must":{"type":{"value":"channels"}},"should":{},"must_not":{"missing":{"field":"sourceId","existence":true,"null_value":true}}}},"fields":["sourceId","callSign","name"],"from":0,"size":10000}
是否可以将 JSON 存储在属性文件中,如果可以,应该使用哪些转义字符
【问题讨论】:
-
您为什么不喜欢使用对象和类并将其解析为使用 GSON 的字符串 jason?通过使用它,您可以将对象存储在任何您想要的位置。
-
您需要引用 }} 作为嵌套 {{ }} 占位符的一部分。所以试试\}\}
-
感谢克劳斯的建议。但是,尽管多次尝试使用 \ 字符转义 } 和 { 出现次数,但我仍然遇到相同的错误。
标签: json apache-camel properties-file