+

Search Tips   |   Advanced Search

Serializing the content of SIMessage

Convert an SIMessage object to a byte array.

To save an SIMessage object in the local file system or in a database, first convert the object to a byte array and format string. We can reconstruct the message from the byte array and format string. To do this.


Tasks

  1. In the application program, record the format string associated with the SIMessage instance. For example:
    String savedFormat=message.getFormat();
    
  2. Call the getDataGraphAsBytes. For example:
    Bytes newDataGraph = message.getNewDataGraph(newFormat);
    
    This method returns a copy of the payload as a byte stream. We can store the bytes and the associated format string, as you require.

  3. Optional: To reconstruct the message, call the method createDataGraph provided by the SIDataGraphFactory API. This method requires a byte array and a format string. For example:
    DataGraph newDataGraph = SIDataGraphFactory.getInstance().createDataGraph(byteArray, newFormat);
    
    This method creates a new data graph by parsing the bytes according to the format passed to the method.


What to do next

Use the newly created datagraph as the payload of an SIMessage instance using the SIMessage setDataGraph() method. For example:
newMessage.setDataGraph(newDataGraph, savedFormat);


Related:

  • Coding tips for mediations programming
  • Message properties support for mediations