Loading

Anypoint Studio interprets well the symbol &#xa needed to escape the "//" but it is not writing this when it is needed

Udgivelsesdato: Oct 6, 2024
Løsning

SYMPTOM

When you are defining a Mule Application that contains a Set Payload, and for a reason inside the Dataweave Script you need to comment a line using the symbol // then an error is appearing in the application:
#%dw 2.0

output application/json

---



//using (fruit = "apple")

{

// "fruit": fruit

"fruit": "banana"

}
 

CAUSE


The Symbol // is needed to be scape using the character  &#xa, but this is not autogenerated by Anypoint Studio, but this is understand right.
The error is in the org.w3c.dom.Element library used to add attributes. In this class we would have to use the setAttributeNode method which allows adding special characters without escaping (for example &) but this is not possible due to an error in the library (https://bugs.eclipse.org/bugs/show_bug.cgi?id=243018) So the only possible solution was to add a warning/error notifying that simple comments cause a conflict.At this time single line comments can only be used when DataWeave is inside a CDATA section. The solution that has been implemented is to show a warning/error and the documentation will be amended to inform users of this situation.

SOLUTION

Modify the XML using the following:
 
<set-payload value='#%dw 2.0&#xa;output application/json&#xa;---&#xa; &#xa;//using (fruit = "apple")&#xa;{&#xa;// "fruit": fruit&#xa;"fruit": "banana"&#xa;}' doc:name="Set Payload" doc:id="cfd55b57-f55f-4983-b80f-3c04d9620ec5" />

Or using the expressiom /* ... */ to comment a line
 
#%dw 2.0
output application/json
---
 
/* sing (fruit = "apple") */
{
 /* "fruit": fruit */ 
"fruit": "banana"
}

 
Vidensartikelnummer

001122337

 
Indlæser
Salesforce Help | Article