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

Closed
KATTA-00 opened this issue Nov 12, 2024 · 2 comments · Fixed by ballerina-platform/module-ballerina-data.xmldata#56
Assignees
Labels
module/data.xmldata Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Status/Blocked Issues that are currently blocked. Type/Bug

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/io;
import ballerinax/financial.iso20022.payments_clearing_and_settlement as pacsIsoRecord;

public function main() returns error? {
    xml newXml = xml `<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.009.001.11"><FICdtTrf><GrpHdr><MsgId>${
""}0ef73893-f1b2-4ae9-b02f-7ffbec25fac</MsgId><CreDtTm>2024-11-18T11:30:43.019889300Z</CreDtTm><NbOfTxs>1</NbOfTxs><SttlmInf><SttlmMtd>INDA</SttlmMtd><InstgRmbrsmntAgt><FinInstnId><LEI>${
""}34554-3049</LEI></FinInstnId></InstgRmbrsmntAgt><InstgRmbrsmntAgtAcct><Id><Othr><SchmeNm/></Othr></Id></InstgRmbrsmntAgtAcct></SttlmInf></GrpHdr><CdtTrfTxInf><PmtId><InstrId>${
""}39857579</InstrId><EndToEndId/></PmtId><IntrBkSttlmAmt><ActiveCurrencyAndAmount_SimpleType Ccy="USD"><ActiveCurrencyAndAmount_SimpleType>${
""}1000000.00</ActiveCurrencyAndAmount_SimpleType></ActiveCurrencyAndAmount_SimpleType></IntrBkSttlmAmt><IntrBkSttlmDt>${
""}2009-05-25</IntrBkSttlmDt><IntrmyAgt1><FinInstnId><BICFI>CITIUS33</BICFI><PstlAdr/></FinInstnId></IntrmyAgt1><Dbtr><FinInstnId/></Dbtr><CdtrAgt><FinInstnId><BICFI>${
""}CITIUS33MIA</BICFI><PstlAdr/></FinInstnId></CdtrAgt><Cdtr><FinInstnId/></Cdtr><InstrForCdtrAgt><Cd>GHYTYY</Cd></InstrForCdtrAgt><InstrForNxtAgt/></CdtTrfTxInf></FICdtTrf></Document>`;
    pacsIsoRecord:Pacs009Document document = check xmldata:parseAsType(newXml);
    io:println(document);
}

Version

distribution-version = "2201.10.0"

@SasinduDilshara
Copy link
Contributor

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

Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@gimantha gimantha added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/data.xmldata Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Status/Blocked Issues that are currently blocked. Type/Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants