This section explains how to work with serialized Java Objects in embedded task forms.

Out of the box, you can only work with Java Objects which are serialized in _JSON format_If Java Classes are serialized using JAX-B, you need to add custom XML parsing and writing logicto the embedded form. Java Objects serialized using Java Serialization cannot be used in forms.

Fetching an existing Serialized Java Object Variable

The Form SDK will only fetch those variables which are actually used in a form. Since a Complex JavaObject is usually not bound to a single input field, we cannot use the cam-variable-name directive.We thus need to fetch the variable programatically:

  1. <script cam-script type="text/form-script">
  2. camForm.on('form-loaded', function() {
  3. // tell the form SDK to fetch the variable named 'invoiceData'
  4. camForm.variableManager.fetchVariable('invoiceData');
  5. });
  6. camForm.on('variables-fetched', function() {
  7. // work with the variable (bind it to the current AngularJS $scope)
  8. $scope.invoiceData = camForm.variableManager.variableValue('invoiceData');
  9. });
  10. </script>

Creating a new Serialized Java Object

In case the variable does not yet exist (for instance in a Start Form), you have to create the variable and specify the necessary meta data in order for the process engine to correctly handle the variable as Java Object.

  1. <script cam-script type="text/form-script">
  2. var dataObject = $scope.dataObject = {};
  3. camForm.on('form-loaded', function() {
  4. // declare variable 'customerData' incuding metadata for serialization
  5. camForm.variableManager.createVariable({
  6. name: 'customerData',
  7. type: 'Object',
  8. value: dataObject,
  9. valueInfo: {
  10. // indicate that object is serialized as json
  11. serializationDataFormat: 'application/json',
  12. // provide classname of java object to map to
  13. objectTypeName: 'org.camunda.bpm.example.CustomerData'
  14. }
  15. });
  16. });
  17. </script>

Full Example

A full example of this feature can be found in the Camunda BPM Examples Repository.

原文: https://docs.camunda.org/manual/7.9/reference/embedded-forms/java-objects/