Create Model: Add CDATA to custom extension elements

We have custom extension elements in our model where we store our metadata. For example, a task can contain a property of exception script in its extension element.

We also have a requirement of creating BPMN Model programmatically and we are doing it as per the below link:

However, when we convert the modelInstance to an XML string, the value in the extension element is not added in CDATA. Is there a way to add the extension element information in the CDATA section?

Attached is the BPMN XML that is generated programmatically. If you see here, there is a property tag inside the extension elements whose value is NOT present in the CDATA section because of which it fails while loading.

The custom property element is added as per the following link:

Here is the code for PDPropertyImpl for reference:

public class PDPropertyImpl extends BpmnModelElementInstanceImpl implements PDProperty {

protected static Attribute<String> nameAttribute;

public static void registerType(ModelBuilder modelBuilder) {
	// removed code for brevity
}

public PDPropertyImpl(ModelTypeInstanceContext instanceContext) {
	super(instanceContext);
}

public String getName() {
	return (String) nameAttribute.getValue(this);
}

public void setName(String camundaName) {
	nameAttribute.setValue(this, camundaName);
}

public String getValue() {
	return this.getTextContent();
}

public void setValue(String value) {
	this.setTextContent(value);
}

}

Can anyone in the team please share the idea on how to fix this issue?

Any help shall be appreciated.

Thanks!

I’d consider it a bug. You should be able to set any value through the API, and the product should encode it properly when exporting XML. I say it not because I’m a camunda expert, but just because it’s a general good programming proctice.

In the meantime you can use getDomElement().addCDataSection