我是作者之一。为了将来参考,在即将发布的 SRU2018 版本(计划于 10 月发布)中,我们已经修改了所有模型抽象层中的所有 JSON API。
SwiftMessage 对象中的 toJson 仍然为标签生成纯名称/值元组。但是,在 MTnnn 类中,toJson 使用 Field 生成带有业务标签的 JSON,例如:
{ "name": "90A",
"qualifier": "DEAL",
"percentageTypeCode": "PRCT",
"price": "102,713552"
},
{ "name": "36B",
"qualifier": "ESTT",
"quantityTypeCode": "AMOR",
"quantity": "7999999,573"
},
{ "name": "97A",
"qualifier": "SAFE",
"account": "0123-0123456-55formatted
}
除了 JSON,您还可以使用可用的 getLabel 和 getValueDisplay 方法迭代字段并打印格式化的名称和值。
例如:
Locale locale = Locale.getDefault();
SwiftMessage sm = SwiftMessage.parse("{1:F01BACOARB1A0B20000000000}{2:I103ADRBNL21XXXXU2}{3:{108:FOOB3926BE868XXX}}{4:\n" +
":20:REFERENCE\n" +
":23B:CRED\n" +
":32A:180730USD1234567,89\n" +
":50A:/12345678901234567890\n" +
"CFIMHKH1XXX\n" +
":59:/12345678901234567890\n" +
"JOE DOE\n" +
"MyStreet 1234\n" +
":71A:OUR\n" +
"-}");
System.out.println("Sender: " + sm.getSender());
System.out.println("Receiver: " + sm.getReceiver() + "\n");
for (Tag tag : sm.getBlock4().getTags()) {
Field field = tag.asField();
System.out.println(Field.getLabel(field.getName(), "103", null, locale));
System.out.println(field.getValueDisplay(locale) + "\n");
}
将产生这个输出:
发件人:BACOARB1A0B2 收件人:ADRBNL21XXXX
Sender's Reference
REFERENCE
Bank Operation Code
CRED
Value Date/Currency/Interbank Settled Amount
Jul 30, 2018 USD 1,234,567.89
Ordering Customer
12345678901234567890 CFIMHKH1XXX
Beneficiary Customer
12345678901234567890 JOE DOE MyStreet 1234
Details of Charges
OUR
组件根据区域设置进行拆分和格式化的位置。如果您还需要每个组件的标签,您可以进一步迭代组件,如下所示:
for (Tag tag : sm.getBlock4().getTags()) {
Field field = tag.asField();
System.out.println("\n" + Field.getLabel(field.getName(), "103", null, locale));
for (int component = 1 ; component <= field.componentsSize() ; component++) {
if (field.getComponent(component) != null) {
System.out.print(field.getComponentLabel(component) + ": ");
System.out.println(field.getValueDisplay(component, locale));
}
}
}
生成其他输出:
Sender's Reference
Reference: REFERENCE
Bank Operation Code
Type: CRED
Value Date/Currency/Interbank Settled Amount
Date: Jul 30, 2018
Currency: USD
Amount: 1,234,567.89
Ordering Customer
Account: 12345678901234567890
BIC: CFIMHKH1XXX
Beneficiary Customer
Account: 12345678901234567890
Name And Address: JOE DOE
Name And Address 2: MyStreet 1234
Details of Charges
Code: OUR
最后,如果您有兴趣,Prowide 的 Integrator 库包括开箱即用的打印输出访问者,可生成 HTML、TXT 和 XML,包括结构化序列和扩展机构信息的 BIC。您可以要求 Prowide 进行试用。