Alisson Gomes
Alisson Gomes

Reputation: 1129

Apache Camel compare string with quotes using spring DSL, how to escape?

How to compare the body content matching (equals or startWith) the value

{"status":"OK"}

How do that?

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

I try:

'{"status":"OK"}'

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

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

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

...

I can do this:

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

But I need equals or startWith as rule operator. :(

I'm using the version apache-camel-2.20.1

Upvotes: 0

Views: 1517

Answers (1)

ltsallas
ltsallas

Reputation: 1948

Camel supports JsonPath, so you should better go with this component in order to compare json.

Add the depencency in pom

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

and then

<camel:choice>
 <camel:when>
  <jsonpath>$[?(@.status=='OK')]]</jsonpath>
  ...
 </camel:when>
</camel:choice>

Upvotes: 3

Related Questions