You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromBalString only works on what toBalString produces for anydata.
Does that mean we have to be restrictive and give errors for all the strings which would not be produced by value:toBalString function when value:fromBalString function is called on them?
E.g.
importballerina/io;
publicfunction main() {
map<string>m= {name:"John", city:"London"};
io:println(m.toBalString()); // {"name":"John","city":"London"}string str =string`{"name":"John","city":"London"}`;
anydata|error ans =str.fromBalString(); // okaystr=string`{"name":"John", "city":"London"}`;
ans=str.fromBalString(); // error, because there is a space after the commastr=string`{name:"John",city:"London"}`;
ans=str.fromBalString(); // error, because the keys are not quoted
}
In the current implementation, value:fromBalString does not give an error when only whitespace characters are in between list/map elements. Since giving an error in those cases are too restrictive for the user and affect user-friendliness, the implementation is continued as it is. Hence the above snippet gives result as follows.
importballerina/io;
publicfunction main() {
map<string>m= {name:"John", city:"London"};
io:println(m.toBalString()); // {"name":"John","city":"London"}string str =string`{"name":"John","city":"London"}`;
anydata|error ans =str.fromBalString(); // okaystr=string`{"name":"John", "city":"London"}`;
ans=str.fromBalString(); // okaystr=string`{name:"John",city:"London"}`;
ans=str.fromBalString(); // error, because the keys are not quoted
}
Closing the issue because further clarification is not needed.
Description:
The spec says that
ballerina-spec/lang/lib/value.bal
Lines 111 to 113 in c88701b
and #135 (comment) also says
Does that mean we have to be restrictive and give errors for all the strings which would not be produced by
value:toBalString
function whenvalue:fromBalString
function is called on them?E.g.
Suggested Labels:
Code sample that shows issue:
Related Issues:
ballerina-platform/ballerina-lang#41700
The text was updated successfully, but these errors were encountered: