Introduction

Sending complex data to and from SAP with K2 connect can be accomplished by using XML data constructed on a schema. This schema is generated during the Service Object configuration. Previously it was the responsibility of the user to generate the XML data correctly or to interpret the XML returned from K2 connect through a SmartObject.

As from K2 connect version 4.6.5, enabling the option to create an XML property during the Service Object configuration, will now create methods to serialize or deserialize these XML data structures.

Executing these methods make it easy to read the data structure and send data into SAP.

Serialization is when the state of an object is changed to a form that can be imported or exported.  Deserialization converts it back to an object.

Example Scenario

Use the steps below as an example on how to use the Serialization and Deserialization functionality. For this example, we will use K2 Designer for Visual Studio 2012 to configure and publish a Service Object mapped to the BAPI_CUSTOMER_GETLIST BAPI. We will then use the SmartObject Service Tester exe to execute the new methods. 

Creating the Service Object and SmartObject

  1. Open K2 Designer for Visual Studio and create an empty K2 Project.
  2. Add a K2 connect Service Object item to the project named Customer.
  3. Click on Add Service.
  4. Open the K2 Service Object Designer from the View menu.
  5. Add the BAPI_CUSTOMER_GETLIST filter to the BAPI Explorer.
  6. Drag the filter to the new service as per the image below.
    Add a filter to the new BAPI service
  7. Click on the Service Method to open the Method Designer.
  8. Click on the IDRange field and click on Show Structure.
  9. Enable the XML Property.
    Enabling the XML property
  10. Publish the Service Object.

Test the Serialize Method

  1. Open the SmartObject Service Tester exe (located by default in [Program Files (x86)]\K2 blackpearl\Bin).
  2. Expand the Service Object Explorer.
  3. Expand the K2 connect Service.
  4. Expand the Service Instance.
  5. Two folders are listed namely Connect Objects and Object Types.
  6. Expand the Object Types folder.
  7. Expand your Service Object created, down to methods. You will see the new methods available.
    SmartObject Services Tester
  8. Expand SmartObject Explorer.
  9. Expand the Serialization folder.
  10. Right click on the CustomerIDRange SmartObject and select Execute SmartObject.
  11. Select the Serialize method to execute. 
  12. Click on Generate Data.
  13. Click on Execute.
  14. Note the Serialized item in the Results. That Serialized String can now be used in other methods.
    Changing the method to serialize

Test the Deserialize Method

  1. To Deserialize the string, copy the Serialized string.
  2. Click on the Method to Execute dropdown and select Deserialize
  3. Paste the Serialized string in the available property.
  4. Click on Execute
  5. Note the Deserialized item.
    Changing the method to deserialize