在Apache Camel中使用JSON作为属性值

问题描述 投票:0回答:1

以下代码行正常工作

.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存储在属性文件中,如果存在,则应使用哪些转义字符(如果有)

json apache-camel properties-file
1个回答
0
投票

不需要simple表达。你可以根据你的例子使用constant。那会很好。前提是您正在使用spring-boot绑定。

.setBody(constant("{{es.stations}}"))
© www.soinside.com 2019 - 2024. All rights reserved.