back Writer (Java to SWIFT)

This feature provides functionality to create a new SWIFT message by populating Java objects, and writing the result as a SWIFT FIN text message.

The creation of a new message basically consists of creating an MT object for the specific message type, and the subsequent addition of fields in an orderly manner.

The order of the fields is very important and should be done accordingly to the standard, the model does not prevent creating incorrect content (Standard compliance validation can be checked with Prowide Integrator)

The following sections provides explanation by examples, creating messages in different common scenarios:

Creating a message with MT classes

The following example shows how to create a new MT103 message using the MT and Field helper classes. This is the easiest and recommended way to create a new message from scratch because the API will automatically fill mandatory header information with proper default values.

The first step is to create the specific MT object and set its general attributes:

	final MT103 m = new MT103();

At this point all message blocks are initialized, and by default the message will be an outgoing message with normal priority.

The next step is adding the message fields. For simple fields the final value can be directly provided as a single String value, and for more complex fields with several subfields (components) the Field helper classes may be used.

m.addField(new Field20("REFERENCE"));
m.addField(new Field23B("CRED"));

Field32A f32A = new Field32A()

Field50A f50A = new Field50A()

Field59 f59 = new Field59()
.setNameAndAddress("JOE DOE");

m.addField(new Field71A("OUR"));

Finally the message() method converts the object into its SWIFT representation:


The output of the above example is:


The same procedure is used to create any type of message, changing the MT103 by any other available implementation.


Creating inner sequences

For more complex messages where fields must be contained in sequences (or sub blocks) some helper API is also provided by the message model. The following example shows how to append a General Information sequence A to an MT542:

SequenceA A = MT542.SequenceA.newInstance(


For boundary based sequences the opening and closing fields 16R and 16S will be automatically included.

Notice sequences should be appended in the correct order, as well as fields inside the sequence block. The API will not control the correctness of the content being generated. The main reason to use this helper sequences API is the constraint provided in the MTnnn classes where only the proper SequenceX inner classes will exist, this way you can rest assure that the appended sequences are part of the specific message type.


Creating a message with specific header content

To create headers with special information, the block's API can be accessed directly. The following example illustrates how to create a message using the low level model layer to create specific headers, overriding the ones created by default in the MT103 constructor.

MT103 m = new MT103();

SwiftBlock1 b1 = new SwiftBlock1();

SwiftBlock2Input b2 = new SwiftBlock2Input();

m.getSwiftMessage().setBlock3(new SwiftBlock3());

In the above example a new and empty message object is created. The basic header (block 1) information is set with specific information, the application header (block 2) is created directly from a suitable string value with all its corresponding attributes pre set, and final an optional user header (block 3) is constructed by adding its tags.

Since the MTnnn classes uses a SwiftMessage instance inside, both level API can be combined; the MTnnn and Fieldnnn classes can be use to create the main content of the message and then the SwiftMessage object can be accessed to add or change specific header or trailer information.

Adding the message trailer block

In most situations there is no need to create the trailer block because it will be added automatically by the FIN interface. However, the API allows the creation of the trailer block as well as any other optional message block as follows:

MT103 m = new MT103();
SwiftBlock5 block5 = new SwiftBlock5();
	block5.addTag(new Tag("MAC", "00000000"));
	block5.addTag(new Tag("PDE", ""));

The resulting block when the object is serialized to FIN will be:


Adding optional blocks

Analogously to the description for Block 5, the same API can be used to create the optional User Header Block (block 3) or to add additional trailers.

The following example will add the user header block to indicate that the message is STP (Straight Through Processing):

MT103 m = new MT103();
SwiftBlock3 block3 = new SwiftBlock3();
	block3.add(new Field119("STP"));

Notice that the user block is optional so it is not initialized by default, an explicit construcor call must be made.

Finally this examples appends an optional application trailer block:

SwiftBlockUser blockUser = new SwiftBlockUser("S");
	blockUser.addTag(new Tag("SAC", ""));
	blockUser.addTag(new Tag("COP", "P"));

More message creation examples can be found at github