从 ApacheCamel header 中的 json-array 提取值
Extract value from json-array in ApacheCamel header
我想使用 jsonpath 从 header 中的 JSON-array 中提取一个值。
headers.barcodes:
[ { "barcodeValue" : "123456789" , "type" : "CODE128" , `"pageNumber" : 1}]
我发现的唯一方法是使用 body 提取值:
<setBody>
<simple>${headers.barcodes}</simple>
</setBody>
<setHeader headerName="barcodeValueOnly">
<jsonpath>$[0].barcodeValue</jsonpath>
</setHeader>
我试过这样通过 header:
<jsonpath>${headers.barcodes}[0].barcodeValue</jsonpath>
但我得到的只是
com.jayway.jsonpath.InvalidPathException: Could not parse token starting at position 2. Expected ?, ', 0-9, *
有没有办法不使用 body 直接将 header 值传递给 jsonpath?
不,这在 jsonpath 上是不可能的,但我们在 xpath 等其他语言上有这样的功能,其中有一个 headerName
选项,您可以配置它来告诉它从 header 而不是消息 body.
所以我已经记录了在下一个版本中添加这样的功能的票证:https://issues.apache.org/jira/browse/CAMEL-11796
我想使用 jsonpath 从 header 中的 JSON-array 中提取一个值。
headers.barcodes:
[ { "barcodeValue" : "123456789" , "type" : "CODE128" , `"pageNumber" : 1}]
我发现的唯一方法是使用 body 提取值:
<setBody>
<simple>${headers.barcodes}</simple>
</setBody>
<setHeader headerName="barcodeValueOnly">
<jsonpath>$[0].barcodeValue</jsonpath>
</setHeader>
我试过这样通过 header:
<jsonpath>${headers.barcodes}[0].barcodeValue</jsonpath>
但我得到的只是
com.jayway.jsonpath.InvalidPathException: Could not parse token starting at position 2. Expected ?, ', 0-9, *
有没有办法不使用 body 直接将 header 值传递给 jsonpath?
不,这在 jsonpath 上是不可能的,但我们在 xpath 等其他语言上有这样的功能,其中有一个 headerName
选项,您可以配置它来告诉它从 header 而不是消息 body.
所以我已经记录了在下一个版本中添加这样的功能的票证:https://issues.apache.org/jira/browse/CAMEL-11796