Search code examples
javaswift-mtmt940

How to convert JSON object received in response to REST Client request to a MT940 Swift text file in Java?


How to convert sample JSON given below to a MT940 txt file:

This JSON would be a bad sample to show but hope you get the gist of it... Just like we have a library in place to parse MT940 strings/txt we also have a library which can help construct a MT940 txt file in Java.

{
  "accNumber":"123356",
  "openBalInd":"D",
  "openBalaDate":"200605",
  "curr":"Dollar",
  "transactions":[
        {
         "amount":""434,
         "credit/debit":"1000",
         "datetime":"20042020"
        },
        {
         "amount":""434,
         "credit/debit":"1000",
         "datetime":"20042020"}]
        }

Solution

  • MT940 is SWIFT message type.

    Your input is JSON and the output is MT940 text file.

    It is always good to have some java model classes representing your json.

    1. Deserialise json input using Jackson to model you gonna use internally.
    2. Use your own library or some third party like https://www.prowidesoftware.com/resources/SWIFT-writer to convert your internal model to MT940
    3. Serialize the result into text file.