ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
137 stars 58 forks source link

Data Binding Issue with JSON to EDI Conversion in EDI tool #6813

Closed RDPerera closed 1 month ago

RDPerera commented 1 month ago

Description:

There appears to be a data binding issue within the JSON to EDI conversion process, leading to inconsistent outputs, especially when handling nested JSON structures. This inconsistency is crucial to address to ensure reliable data transformation.

Steps to Reproduce:

  1. Generate a package for X12 850 transaction set using libgen.
  2. Run the REST client using bal run
  3. Input the following JSON data into the generated REST client for 850 X12 transaction set.
curl --location 'http://localhost:9090/ediParser/objects/850' \
--header 'Content-Type: application/json' \
--data-raw '{
    "X12_FunctionalGroup": {
        "FunctionalGroupHeader": {
            "code": "GS",
            "GS01__FunctionalIdentifierCode": "PO",
            "GS02__ApplicationSendersCode": "SENDERID",
            "GS03__ApplicationReceiversCode": "RECEIVERID",
            "GS04__Date": "20240802",
            "GS05__Time": "1705",
            "GS06__GroupControlNumber": 1.0,
            "GS07__ResponsibleAgencyCode": "X",
            "GS08__VersionReleaseIndustryIdentifierCode": "004010"
        },
        "X12_004010_850": {
            "TransactionSetHeader": {
                "code": "ST",
                "ST01__TransactionSetIdentifierCode": "850",
                "ST02__TransactionSetControlNumber": "0001"
            },
            "BeginningSegmentforPurchaseOrder": {
                "code": "BEG",
                "BEG01__TransactionSetPurposeCode": "00",
                "BEG02__PurchaseOrderTypeCode": "NE",
                "BEG03__PurchaseOrderNumber": "4500012345",
                "BEG04__ReleaseNumber": "",
                "BEG05__Date": "20240802"
            },
            "ReferenceIdentification": {
                "code": "REF",
                "REF01__ReferenceIdentificationQualifier": "DP",
                "REF02__ReferenceIdentification": "038"
            },
            "AdministrativeCommunicationsContact": {
                "code": "PER",
                "PER01__ContactFunctionCode": "BD",
                "PER02__Name": "John Doe",
                "PER03__CommunicationNumberQualifier": "TE",
                "PER04__CommunicationNumber": "1234567890",
                "PER05__CommunicationNumberQualifier": "EM",
                "PER06__CommunicationNumber": "john.doe@example.com"
            },
            "FOBRelatedInstructions": {
                "code": "FOB",
                "FOB01__ShipmentMethodofPayment": "CC"
            },
            "TermsofSaleDeferredTermsofSale": {
                "code": "ITD",
                "ITD01__TermsTypeCode": "01",
                "ITD02__TermsBasisDateCode": "3",
                "ITD03__TermsDiscountPercent": "2",
                "ITD04__TermsDiscountDueDate": "",
                "ITD05__TermsDiscountDaysDue": 30.0,
                "ITD06__TermsNetDueDate": "",
                "ITD07__TermsNetDays": 31.0
            },
            "DateTimeReference": {
                "code": "DTM",
                "DTM01__DateTimeQualifier": "002",
                "DTM02__Date": "20240902"
            },
            "Loop_1_0310": {
                "Name": {
                    "code": "N1",
                    "N101__EntityIdentifierCode": "ST",
                    "N102__Name": "SHIP TO NAME",
                    "N103__IdentificationCodeQualifier": "92",
                    "N104__IdentificationCode": "SHIP TO CODE"
                },
                "AddressInformation": {
                    "code": "N3",
                    "N301__AddressInformation": "123 SHIP TO ADDRESS"
                },
                "GeographicLocation": {
                    "code": "N4",
                    "N401__CityName": "CITY",
                    "N402__StateorProvinceCode": "STATE",
                    "N403__PostalCode": "12345",
                    "N404__CountryCode": "US"
                }
            },
            "Loop_2_0010": {
                "BaselineItemData": {
                    "code": "PO1",
                    "PO101__AssignedIdentification": "1",
                    "PO102__QuantityOrdered": "10",
                    "PO103__UnitorBasisforMeasurementCode": "EA",
                    "PO104__UnitPrice": "15.00",
                    "PO105__BasisofUnitPriceCode": "",
                    "PO106__ProductServiceIDQualifier": "BP",
                    "PO107__ProductServiceID": "123456789012",
                    "PO108__ProductServiceIDQualifier": "VP",
                    "PO109__ProductServiceID": "9876543210",
                    "PO110__ProductServiceIDQualifier": "UP",
                    "PO111__ProductServiceID": "123456789012"
                },
                "Loop_2_0050": {
                    "ProductItemDescription": {
                        "code": "PID",
                        "PID01__ItemDescriptionType": "F",
                        "PID02__ProductProcessCharacteristicCode": "",
                        "PID03__AgencyQualifierCode": "",
                        "PID04__ProductDescriptionCode": "",
                        "PID05__Description": "PRODUCT DESCRIPTION"
                    }
                },
                "ItemPhysicalDetails": {
                    "code": "PO4",
                    "PO401__Pack": 1.0,
                    "PO402__Size": "CA",
                    "PO403__UnitorBasisforMeasurementCode": "20",
                    "PO404__PackagingCode": "LB"
                }
            },
            "Loop_3_0010": {
                "TransactionTotals": {
                    "code": "CTT",
                    "CTT01__NumberofLineItems": 1.0
                }
            },
            "TransactionSetTrailer": {
                "code": "SE",
                "SE01__NumberofIncludedSegments": 16.0,
                "SE02__TransactionSetControlNumber": "0001"
            }
        },
        "FunctionalGroupTrailer": {
            "code": "GE",
            "GE01__NumberofTransactionSetsIncluded": 1.0,
            "GE02__GroupControlNumber": 1.0
        }
    },
    "InterchangeControlTrailer": {
        "code": "IEA",
        "IEA01__NumberofIncludedFunctionalGroups": 1.0,
        "IEA02__InterchangeControlNumber": 1.0
    }
}'

Expected Result: The EDI output should accurately reflect all nested JSON fields in the correct EDI segments.

Actual Result: The conversion output data binding error. error: {ballerina}TypeCastError {"message":"incompatible types: 'map<json>' cannot be cast to 'Hello:EDI_850_X12_004010_850'"}

Suggested Actions:

github-actions[bot] commented 1 month ago

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.