Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting Issue when converting an XML to a Ballerina record that includes Enums #7355

Open
KATTA-00 opened this issue Nov 12, 2024 · 1 comment

Comments

@KATTA-00
Copy link

KATTA-00 commented Nov 12, 2024

Description

When converting an XML to a Ballerina record, if there is an enum in the record there area compiled time error.

Code:

@test:Config {}
function testTransformPain008DocumentToMT104() returns error? {
    xml documentXML = xml `
        <Pain008Document>
            <CstmrDrctDbtInitn>
                <GrpHdr>
                    <MsgId>EXAMPLE123456</MsgId>
                    <CreDtTm>2024-11-06T09:30:00Z</CreDtTm>
                    <NbOfTxs>2</NbOfTxs>
                    <CtrlSum>1500.00</CtrlSum>
                    <InitgPty>
                        <Nm>ABC Corporation</Nm>
                        <Id>
                            <OrgId>
                                <AnyBIC>ABCDEF12</AnyBIC>
                            </OrgId>
                        </Id>
                    </InitgPty>
                </GrpHdr>
                <PmtInf>
                    <PmtInfId>PMT20241106</PmtInfId>
                    **<PmtMtd>DD</PmtMtd>**
                    <BtchBookg>true</BtchBookg>
                    <NbOfTxs>2</NbOfTxs>
                    <CtrlSum>1500.00</CtrlSum>
                    <PmtTpInf>
                        <InstrPrty>NORM</InstrPrty>
                        <SvcLvl>
                            <Cd>SEPA</Cd>
                        </SvcLvl>
                    </PmtTpInf>
                    <ReqdColltnDt>2024-11-07</ReqdColltnDt>
                    <Cdtr>
                        <Nm>XYZ Ltd</Nm>
                        <PstlAdr>
                            <Ctry>DE</Ctry>
                            <AdrLine>123 Main Street</AdrLine>
                        </PstlAdr>
                    </Cdtr>
                    <CdtrAcct>
                        <Id>
                            <IBAN>DE89370400440532013000</IBAN>
                        </Id>
                    </CdtrAcct>
                    <CdtrAgt>
                        <FinInstnId>
                            <BICFI>DEUTDEFF</BICFI>
                        </FinInstnId>
                    </CdtrAgt>
                    <ChrgBr>SLEV</ChrgBr>
                    <DrctDbtTxInf>
                        <PmtId>
                            <InstrId>INSTR12345</InstrId>
                            <EndToEndId>ETOE12345</EndToEndId>
                        </PmtId>
                        <InstdAmt Ccy="EUR">1000.00</InstdAmt>
                        <DrctDbtTx>
                            <MndtRltdInf>
                                <MndtId>MANDATE123</MndtId>
                                <DtOfSgntr>2024-01-01</DtOfSgntr>
                            </MndtRltdInf>
                        </DrctDbtTx>
                        <DbtrAgt>
                            <FinInstnId>
                                <BICFI>DEUTDEBB</BICFI>
                            </FinInstnId>
                        </DbtrAgt>
                        <Dbtr>
                            <Nm>John Doe</Nm>
                            <PstlAdr>
                                <Ctry>DE</Ctry>
                                <AdrLine>456 Sample Avenue</AdrLine>
                            </PstlAdr>
                        </Dbtr>
                        <DbtrAcct>
                            <Id>
                                <IBAN>DE62370400440532013001</IBAN>
                            </Id>
                        </DbtrAcct>
                        <RmtInf>
                            <Ustrd>Invoice 12345</Ustrd>
                        </RmtInf>
                    </DrctDbtTxInf>
                    <DrctDbtTxInf>
                        <PmtId>
                            <InstrId>INSTR67890</InstrId>
                            <EndToEndId>ETOE67890</EndToEndId>
                        </PmtId>
                        <InstdAmt Ccy="EUR">500.00</InstdAmt>
                        <DrctDbtTx>
                            <MndtRltdInf>
                                <MndtId>MANDATE678</MndtId>
                                <DtOfSgntr>2024-05-15</DtOfSgntr>
                            </MndtRltdInf>
                        </DrctDbtTx>
                        <DbtrAgt>
                            <FinInstnId>
                                <BICFI>DEUTDEBB</BICFI>
                            </FinInstnId>
                        </DbtrAgt>
                        <Dbtr>
                            <Nm>Jane Smith</Nm>
                            <PstlAdr>
                                <Ctry>DE</Ctry>
                                <AdrLine>789 Test Blvd</AdrLine>
                            </PstlAdr>
                        </Dbtr>
                        <DbtrAcct>
                            <Id>
                                <IBAN>DE89370400440532013002</IBAN>
                            </Id>
                        </DbtrAcct>
                        <RmtInf>
                            <Ustrd>Invoice 67890</Ustrd>
                        </RmtInf>
                    </DrctDbtTxInf>
                </PmtInf>
            </CstmrDrctDbtInitn>
        </Pain008Document>
        `;
    painIsoRecord:Pain008Document pain008Message = <painIsoRecord:Pain008Document>(check swiftmx:fromIso20022(documentXML, painIsoRecord:Pain008Document));
}

Error:

error {ballerina/data.xmldata:1}Error ("'string' value 'DD' cannot be converted to 'ballerinax/financial.iso20022.payment_initiation:1:PaymentMethod2Code'")
                                callableName: parseAsType moduleName: ballerina.data.xmldata.1 fileName: xml_api.bal lineNumber: 86
                                callableName: fromIso20022 moduleName: ballerinax.financial.iso20022.1 fileName: parser.bal lineNumber: 13
                                callableName: testTransformPain008DocumentToMT104$lambda6$ moduleName: ballerinax.financial.ISO20022ToSwiftMT$test.0.tests.test_execute-generated_1 fileName: tests/test_execute-generated_1.bal lineNumber: 10

Steps to Reproduce

import ballerina/test;
import ballerinax/financial.iso20022 as swiftmx;
import ballerinax/financial.iso20022.payment_initiation as painIsoRecord;
import ballerinax/financial.iso20022.payments_clearing_and_settlement as pacsIsoRecord;
import ballerinax/financial.swift.mt as swiftmt;

@test:Config {}
function testTransformPain008DocumentToMT104() returns error? {
    xml documentXML = xml `
        <Pain008Document>
            <CstmrDrctDbtInitn>
                <GrpHdr>
                    <MsgId>EXAMPLE123456</MsgId>
                    <CreDtTm>2024-11-06T09:30:00Z</CreDtTm>
                    <NbOfTxs>2</NbOfTxs>
                    <CtrlSum>1500.00</CtrlSum>
                    <InitgPty>
                        <Nm>ABC Corporation</Nm>
                        <Id>
                            <OrgId>
                                <AnyBIC>ABCDEF12</AnyBIC>
                            </OrgId>
                        </Id>
                    </InitgPty>
                </GrpHdr>
                <PmtInf>
                    <PmtInfId>PMT20241106</PmtInfId>
                    <PmtMtd>DD</PmtMtd>
                    <BtchBookg>true</BtchBookg>
                    <NbOfTxs>2</NbOfTxs>
                    <CtrlSum>1500.00</CtrlSum>
                    <PmtTpInf>
                        <InstrPrty>NORM</InstrPrty>
                        <SvcLvl>
                            <Cd>SEPA</Cd>
                        </SvcLvl>
                    </PmtTpInf>
                    <ReqdColltnDt>2024-11-07</ReqdColltnDt>
                    <Cdtr>
                        <Nm>XYZ Ltd</Nm>
                        <PstlAdr>
                            <Ctry>DE</Ctry>
                            <AdrLine>123 Main Street</AdrLine>
                        </PstlAdr>
                    </Cdtr>
                    <CdtrAcct>
                        <Id>
                            <IBAN>DE89370400440532013000</IBAN>
                        </Id>
                    </CdtrAcct>
                    <CdtrAgt>
                        <FinInstnId>
                            <BICFI>DEUTDEFF</BICFI>
                        </FinInstnId>
                    </CdtrAgt>
                    <ChrgBr>SLEV</ChrgBr>
                    <DrctDbtTxInf>
                        <PmtId>
                            <InstrId>INSTR12345</InstrId>
                            <EndToEndId>ETOE12345</EndToEndId>
                        </PmtId>
                        <InstdAmt Ccy="EUR">1000.00</InstdAmt>
                        <DrctDbtTx>
                            <MndtRltdInf>
                                <MndtId>MANDATE123</MndtId>
                                <DtOfSgntr>2024-01-01</DtOfSgntr>
                            </MndtRltdInf>
                        </DrctDbtTx>
                        <DbtrAgt>
                            <FinInstnId>
                                <BICFI>DEUTDEBB</BICFI>
                            </FinInstnId>
                        </DbtrAgt>
                        <Dbtr>
                            <Nm>John Doe</Nm>
                            <PstlAdr>
                                <Ctry>DE</Ctry>
                                <AdrLine>456 Sample Avenue</AdrLine>
                            </PstlAdr>
                        </Dbtr>
                        <DbtrAcct>
                            <Id>
                                <IBAN>DE62370400440532013001</IBAN>
                            </Id>
                        </DbtrAcct>
                        <RmtInf>
                            <Ustrd>Invoice 12345</Ustrd>
                        </RmtInf>
                    </DrctDbtTxInf>
                    <DrctDbtTxInf>
                        <PmtId>
                            <InstrId>INSTR67890</InstrId>
                            <EndToEndId>ETOE67890</EndToEndId>
                        </PmtId>
                        <InstdAmt Ccy="EUR">500.00</InstdAmt>
                        <DrctDbtTx>
                            <MndtRltdInf>
                                <MndtId>MANDATE678</MndtId>
                                <DtOfSgntr>2024-05-15</DtOfSgntr>
                            </MndtRltdInf>
                        </DrctDbtTx>
                        <DbtrAgt>
                            <FinInstnId>
                                <BICFI>DEUTDEBB</BICFI>
                            </FinInstnId>
                        </DbtrAgt>
                        <Dbtr>
                            <Nm>Jane Smith</Nm>
                            <PstlAdr>
                                <Ctry>DE</Ctry>
                                <AdrLine>789 Test Blvd</AdrLine>
                            </PstlAdr>
                        </Dbtr>
                        <DbtrAcct>
                            <Id>
                                <IBAN>DE89370400440532013002</IBAN>
                            </Id>
                        </DbtrAcct>
                        <RmtInf>
                            <Ustrd>Invoice 67890</Ustrd>
                        </RmtInf>
                    </DrctDbtTxInf>
                </PmtInf>
            </CstmrDrctDbtInitn>
        </Pain008Document>
        `;
    painIsoRecord:Pain008Document pain008Message = <painIsoRecord:Pain008Document>(check swiftmx:fromIso20022(documentXML, painIsoRecord:Pain008Document));
}

Version

distribution-version = "2201.10.0"

@SasinduDilshara
Copy link

We needs to support Enums and Singelton values for data.xmldata module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants