-
Notifications
You must be signed in to change notification settings - Fork 758
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
Comments
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);
} |
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);
} |
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. |
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
Json:
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
The text was updated successfully, but these errors were encountered: