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

[Bug]: Data Binding doesn't Work as Expected for Records with Escape Characters #41633

Closed
DimuthuMadushan opened this issue Nov 2, 2023 · 3 comments · Fixed by #41640
Closed
Assignees
Labels
Priority/Blocker Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug
Milestone

Comments

@DimuthuMadushan
Copy link
Contributor

Description

Consider the following sample. The Json to record conversion returns error: {ballerina/lang.value}ConversionError. After replacing the \- with _, it works as expected.

Steps to Reproduce

import ballerina/io;

public type Copybook record {
    DFHCOMMAREA DFHCOMMAREA?;
};

public type DFHCOMMAREA record {
    record {
        string MI\-HDR\-VERSION?;
        string MI\-HDR\-MSGID?;
        string MI\-HDR\-LOGGINGID?;
        record {
            string MI\-HDR\-REPLYQMGR?;
        }[2] MI\-HDR\-REPLYSTACK?;
    } BROKER\-MESSAGE\-AREA?;
};

public function main() returns error? {
    json 'record = check io:fileReadJson("result.json");
    map<json> mapJson = check 'record.ensureType();
    Copybook dfhcommarea = check mapJson.cloneWithType();
    io:println(dfhcommarea.DFHCOMMAREA?.BROKER\-MESSAGE\-AREA);
}

Json:

{
    "DFHCOMMAREA": {
        "BROKER-MESSAGE-AREA": {
            "MI-HDR-VERSION": "2",
            "MI-HDR-MSGID":"3238763233323598798798712321187612",
            "MI-HDR-LOGGINGID": "Z5118761-Z"
        }
    }
}

Affected Version(s)

2201.8.0

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Nov 2, 2023
@MaryamZi MaryamZi added Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime and removed needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Nov 2, 2023
@HindujaB HindujaB self-assigned this Nov 3, 2023
@HindujaB
Copy link
Contributor

HindujaB commented Nov 3, 2023

A possible workaround is as follows,

import ballerina/io;

public type Copybook record {
    DFHCOMMAREA DFHCOMMAREA?;
};

type Rec record {
    string MI\-HDR\-VERSION?;
    string MI\-HDR\-MSGID?;
    string MI\-HDR\-LOGGINGID?;
    record {
        string MI\-HDR\-REPLYQMGR?;
    }[2] MI\-HDR\-REPLYSTACK?;
};

public type DFHCOMMAREA record {
    Rec BROKER\-MESSAGE\-AREA?;
};

public function main() returns error? {
    json rec = check io:fileReadJson("result.json");
    map<json> mapJson = check rec.ensureType();
    Copybook dfhcommarea = check mapJson.cloneWithType();
    io:println(dfhcommarea.DFHCOMMAREA?.BROKER\-MESSAGE\-AREA);
}

@HindujaB
Copy link
Contributor

HindujaB commented Nov 22, 2023

The following also failing.

import ballerina/io;
import ballerina/lang.value;

public type Copybook record {
    DFH\-COMMAREA DFH\-COMMAREA?; // note the type name contains \-
};

public type DFH\-COMMAREA record {
    record {
        string MI\-HDR\-VERSION?;
        string MI\-HDR\-MSGID?;
        string MI\-HDR\-LOGGINGID?;
        record {
            string MI\-HDR\-REPLYQMGR?;
        }[2] MI\-HDR\-REPLYSTACK?;
    } BROKER\-MESSAGE\-AREA?;
};

public function main() returns error? {
    string s = string `{
    "DFH-COMMAREA": {
        "BROKER-MESSAGE-AREA": {
            "MI-HDR-VERSION": "2",
            "MI-HDR-MSGID":"3238763233323598798798712321187612",
            "MI-HDR-LOGGINGID": "Z5118761-Z"
        }
    }
    }`;
    json rec = checkpanic value:fromJsonString(s);
    map<json> mapJson = check rec.ensureType();
    Copybook dfh\-commarea = check mapJson.cloneWithType();
    io:println(dfh\-commarea.DFH\-COMMAREA?.BROKER\-MESSAGE\-AREA);
}

@DimuthuMadushan DimuthuMadushan removed this from the 2201.8.3 milestone Nov 22, 2023
@github-project-automation github-project-automation bot moved this from PR Sent to Done in Ballerina Team Main Board Nov 23, 2023
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.

@warunalakshitha warunalakshitha added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Nov 23, 2023
@sahanHe sahanHe added this to the 2201.8.4 milestone Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority/Blocker Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug
Projects
Archived in project
7 participants