You can use formatters for the following functions:
Defining Formatter in xml file
Formatter instance is created from an xml definition. Generally speaking, a formatter definition defines the rule to execute formatting and unformatting. It has the same structure with the corresponding structured data, and the formatter instance created from the formatter definition is capable of formatting and unformatting the corresponding structured data. Each formatter definition has a key to differentiate itself from others.
Getting Formatter instance from a key
Get a formatter instance from a key. In this way, the instance will be cached for reuse, which will help reduce the frequency of reading the definition files. In fact, each formatter instance is identified by the key, and there is only one formatter instance for one key. The instance might be required to format many instances of structured data at the same time, so the status of formatting or unformatting process should not be kept in the instance of formatter.
Translating (formatting) structured data into a host message
Use the formatter to translate (format) the structured data into a host message. The Formatter instance will process the structured data according to the predefined rule, and put the data content into a flat String or byte[], so that it can be recognized by the host application.
Translating (unformatting) a host message into structured data
Given a host message (a flat String or byte[]) and an instance of structured data (which is not populated with data content), the Formatter instance will parse the message according to the predefined rule, and populate the data content contained in the host message into the instance of structured data.
Translating (formatting) structured data into XML
Given the structured data with data content populated, the formatter instance will processes it according to the predefined rule and translate it into an XML String.
Translating (unformatting) XML into structured data
Given an XML String and an empty instance of structured data, the formatter instance will parse the XML String according to the predefined rule and populate the instance of structured data with data content in the XML String.
Translating (formatting) structured data into JSON
Given the structured data with data content populated, the formatter instance will process it according to the predefined rule and translate it into a JSON String.
Translating (unformatting) JSON into structured data
Given a JSON String and an empty instance of structured data, the formatter instance will parse the JSON String according to the predefined rule and populate the instance of structured data with the data content in the JSON String.
Adding extension to Formatter according to your requirements
UNICOM® Digital Transformation Toolkit (UDTT™) includes a set of FormatElements, which are the elements of formatters. You can implement your own FormatterElement. Besides extending to FormatElement, you can also extend to Formatter so that it can support other kinds of structured data.