Claus Ibsen created CAMEL-25326:
-----------------------------------

             Summary: camel-datasonnet - cml.variable()/cml.header() cannot 
read a JSON or XML string as structured data
                 Key: CAMEL-25326
                 URL: https://issues.apache.org/jira/browse/CAMEL-25326
             Project: Camel
          Issue Type: Improvement
            Reporter: Claus Ibsen


{{cml.variable()}}, {{cml.header()}} and {{cml.exchangeProperty()}} read the 
value as a Java object ({{CML.valFrom}} uses {{application/x-java-object}} 
unless the value is already a Document). A variable holding JSON as a string, 
which is the usual case after an enrich or a pollEnrich that stores its result 
in a variable, therefore stays a string:

{code}
cml.variable('other').name                  // fails: attempted to index a 
string with string name
std.parseJson(cml.variable('other')).name   // works
{code}

For XML there is no equally simple way. This makes mappings that join the body 
with a second source awkward, and they are a common data-mapping case. 
DataWeave's {{read()}} is also translated to {{std.parseJson}}, which only 
works for JSON.

Proposal: an optional media type argument, e.g. {{cml.variable('other', 
'application/json')}} / {{cml.header('x', 'application/xml')}}, that reads the 
value with the matching DataSonnet format. Possibly also use a Content-Type 
stored with the value when there is one. Document it in the datasonnet-language 
page, with an enrich-and-join example.

_Claude Code on behalf of davsclaus_



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

Reply via email to