[
https://issues.apache.org/jira/browse/CAMEL-24230?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-24230:
--------------------------------
Fix Version/s: 4.22.0
> jsonpath language with writeAsString=true returns Map instead of JSON String
> for object expressions
> ---------------------------------------------------------------------------------------------------
>
> Key: CAMEL-24230
> URL: https://issues.apache.org/jira/browse/CAMEL-24230
> Project: Camel
> Issue Type: Bug
> Components: camel-jsonpath
> Affects Versions: 4.21.0
> Reporter: Raymond
> Assignee: Omar Atie
> Priority: Minor
> Fix For: 4.22.0
>
>
> I have the following json:
> {code:java}
> {
> "args": {
> "age": 30,
> "name": "Alice"
> },
> "headers": {
> "Accept":
> "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
>
> "Accept-Encoding": "gzip, deflate, br, zstd",
> "Accept-Language": "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7",
> "Host": "httpbin.org",
> "Priority": "u=0, i",
> "Sec-Ch-Ua": "\"Google Chrome\";v=\"149\", \"Chromium\";v=\"149\",
> \"Not)A;Brand\";v=\"24\"",
> "Sec-Ch-Ua-Mobile": "?0",
> "Sec-Ch-Ua-Platform": "\"Windows\"",
> "Sec-Fetch-Dest": "document",
> "Sec-Fetch-Mode": "navigate",
> "Sec-Fetch-Site": "none",
> "Sec-Fetch-User": "?1",
> "Upgrade-Insecure-Requests": "1",
> "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)
> AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36",
> "X-Amzn-Trace-Id": "Root=1-6a2c1b7f-2c55fb0260804ec036ffb630"
> },
> "origin": "178.227.111.11",
> "url": "https://httpbin.org/get?name=Alice&age=30"
> }{code}
> And the following jsonpath:
>
> {code:java}
> $.args
> {code}
> The online jsonpath (https://jsonpath.com/) tester gives:
>
> {code:java}
> [ { "age": 30, "name": "Alice" }]{code}
> However when evaluating the same jsonpath in Apache Camel (with jsonpath on
> the classpath):
> {code:java}
> <setHeaders>
> <setHeader name="NewBody">
> <jsonpath writeAsString="true">$.args</jsonpath>
> </setHeader>
> </setHeaders> {code}
> I get:
> {{}}
> {code:java}
> {age=30, name="Alice"} {code}
> {{Thus the values are correct, but the keys not. }}When using the
> {{jsonpath}} expression language with {{writeAsString="true"}} on a query
> that evaluates to a single JSON Object (e.g., {{{}$.args{}}}),
> {{JsonPathEngine}} returns a {{java.util.Map<Object, Object>}} where the
> values are serialized, rather than serializing the entire Map into a valid
> JSON string.
> *Summary*
> {{}}
> *Expected Behavior:* {{<jsonpath writeAsString="true">$.args</jsonpath>}}
> should return a {{java.lang.String}} containing valid JSON (e.g.,
> {{{}{"age":30,"name":"Alice"}{}}}).
> {{}}
> *Actual Behavior:* It returns a {{java.util.Map}} whose {{.toString()}}
> evaluates to {{{}{age=30, name="Alice"}{}}}.
> {{}}
> *Possible Root Cause:* In {{{}org.apache.camel.jsonpath.JsonPathEngine{}}},
> the {{answer instanceof Map}} branch iterates over entries and stringifies
> {{{}entry.getValue(){}}}, but returns the {{Map}} instance itself instead of
> passing the entire {{answer}} object through
> {{{}adapter.writeAsString(answer, exchange){}}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)