Raymond created CAMEL-23381:
-------------------------------

             Summary: simple language - Set the resulttype directly on xpath 
and jsonpath
                 Key: CAMEL-23381
                 URL: https://issues.apache.org/jira/browse/CAMEL-23381
             Project: Camel
          Issue Type: Improvement
          Components: camel-core
            Reporter: Raymond


By default jsonpath and xpath return an object:

{{}}
{code:java}
jsonpath(exp)
jsonpath(input,exp)

xpath(exp)
xpath(input,exp){code}

Mostly you want to explicitly get the type (string, int, boolean). Since 4.18.x 
this has become a bit more flexible, and developers can do something like this:


{code:java}
$price1 := ${xpath(//food[name='food1']/price/text())} ~> ${convertTo(int)}; 
{code}

It would be however convenient to set the resultType directly on the function:


{code:java}
jsonpath(exp, resultType)
jsonpath(input,exp, resultType)

xpath(exp, resultType)
xpath(input,exp, resultType)

{code}
{{Setting the resultType is in aligment with the rest of the Simple language. }}

{{Sidenote:}}

{{{}I also saw some other ways to define to type in other languages 
like:{}}}{{{}{}}}
 * {{int:${xpath(//food/price)}}}

 * {{${xpath(//food/price).toInteger()}}}

 * {{${xpath(...) as int}}}

One of the above maybe a bit more elegant, but is of course not the standard 
syntax until now.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to