Apache Camel使用spring DSL比较字符串与引号,如何逃脱?

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

如何比较身体内容匹配(equalsstartWith)的值

{"status":"OK"}

怎么样?

<camel:choice>
 <camel:when>
  <simple>${in.body} == '{"status":"OK"}'</simple>
  ...
 </camel:when>
</camel:choice>

我尝试:

'{"status":"OK"}'

'{\x22status\x22:\x22OK\x22}'

'\{"status":"OK"\}'

'{"status":"OK"\}'

...

我可以做这个:

<simple>${in.body} contains '{"status":"OK"'</simple>

但我需要equalsstartWith作为规则运营商。 :(

我正在使用版本apache-camel-2.20.1

apache-camel
1个回答
2
投票

Camel支持JsonPath,所以你应该更好地使用这个组件来比较json。

在pom中添加依赖项

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-jsonpath</artifactId>
  <version>x.x.x</version>
</dependency>

然后

<camel:choice>
 <camel:when>
  <jsonpath>$[?(@.status=='OK')]]</jsonpath>
  ...
 </camel:when>
</camel:choice>
© www.soinside.com 2019 - 2024. All rights reserved.