Formatters are what the toolkit uses to exchange data between toolkit entities such as operations, contexts, and services. Each formatter converts a specific data item into a string representation of the data item and parses a string into a specific data item. In this way, the toolkit uses formatters to build messages to do things such as sending a transaction to the host, writing a journal record, printing a form. Formatters enable applications to interact with many various entities without requiring changes to the application. For example, an application may use different formatters to send the same data to the electronic journal or to a financial printer.
Formatters are used to format (translate) structured data into a Host Message (usually a String to an Array of bytes), and unformat (translate) a Host Message into structured data. The Host Message complies with the format of the Host Application, while the structured data can be various kinds of data in Java World (such as Java Bean, Context, and Service Data Object).
In a word, formatter is the message translator between Java Application and Host Application as shown in the following figure:
Besides formatting (translating) structured data into a Host Message, the Formmaters can also format (translate) the structured data into XML or JSON, and unformat (translate) XML and JSON message into structured data.