@JacksonXmlRootElement(localName = "COMMAND")
data class AirtelExpressRequest(
@field:JacksonXmlProperty(localName = "TYPE")
val type: String,
@field:JacksonXmlProperty(localName = "INTERFACEID")
val interfaceId: String,
@field:JacksonXmlProperty(localName = "MSISDN")
val msisdn: String,
@field:JacksonXmlProperty(localName = "MSISDN2")
val msisdn2: String,
@field:JacksonXmlProperty(localName = "AMOUNT")
val amount: Int,
@field:JacksonXmlProperty(localName = "MEMO")
val memo: String,
@field:JacksonXmlProperty(localName = "EXTTRID")
val externalTxnId: String,
@field:JacksonXmlProperty(localName = "MERCHANT_TXN_ID")
val merchantTxnId: String,
@field:JacksonXmlProperty(localName = "IS_TRANS_UNIQUE_CHECK_REQUIRED")
val isUnique: String = "Y",
@field:JacksonXmlProperty(localName = "REFERENCE")
val reference: String,
@field:JacksonXmlProperty(localName = "serviceType")
val serviceType: String,
@field:JacksonXmlProperty(localName = "USERNAME")
val username: String,
@field:JacksonXmlProperty(localName = "PASSWORD")
val password: String
)
使用
XmlMapper
之后,您可以继续并将数据类序列化为xml
。
val xmlMapper = XmlMapper(
JacksonXmlModule().apply { setDefaultUseWrapper(false) }
).apply {
enable(SerializationFeature.INDENT_OUTPUT)
val strObject = Request(
type = "MERCHPAY",
interfaceId = "DATABUNDLES",
msisdn = "733204938",
msisdn2 = "100001929",
amount = 1_000,
externalTxnId = "07026984141550752666",
merchantTxnId = "07026984141550752666",
reference = "Testing transaction",
memo = "Enter the PIN for payment of 1000 to purchase testing transaction",
serviceType = "MERCHPAY",
username = "abcd",
password = "abcd123"
val xml = xmlMapper.writeValueAsString(strObject)
Output
<COMMAND>
<TYPE>MERCHPAY</TYPE>
<INTERFACEID>DATABUNDLES</INTERFACEID>
<MSISDN>733204938</MSISDN>
<MSISDN2>100001929</MSISDN2>
<AMOUNT>1000</AMOUNT>
<MEMO>Enter the PIN for payment of 1000 to purchase testing transaction</MEMO>
<EXTTRID>07026984141550752666</EXTTRID>
<MERCHANT_TXN_ID>07026984141550752666</MERCHANT_TXN_ID>