Skip to content

Commit

Permalink
Fix review suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 committed Sep 18, 2024
1 parent aef5283 commit ea9d9eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
24 changes: 9 additions & 15 deletions ballerina/json_api.bal
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,17 @@ public isolated function parseStream(stream<byte[], error?> s, Options options =

# Converts a value of type `anydata` to `json`.
#
# + j - Source anydata value
# + return - representation of `j` as value of type json
public isolated function toJson(anydata j) returns json {
if j is anydata[] {
json[] arr = from anydata elem in j
# + v - Source anydata value
# + return - representation of `v` as value of type json
public isolated function toJson(anydata v) returns json {
if v is anydata[] {
return from anydata elem in v
select toJson(elem);
return arr;
} else if j is map<anydata> {
map<json> m = {};
foreach var [key, v] in j.entries() {
string newKey = getNameAnnotation(j, key);
m[newKey] = toJson(v);
}
return m;
} else {
return j.toJson();
} else if v is map<anydata> {
return map from var [key, feild] in v.entries()
select [getNameAnnotation(v, key), toJson(feild)];
}
return v.toJson();
}

isolated function getNameAnnotation(map<anydata> data, string key) returns string = @java:Method {'class: "io.ballerina.lib.data.jsondata.json.Native"} external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public static Object parseStream(Environment env, BStream json, BMap<BString, Ob
return null;
}

public static BString getNameAnnotation(BMap<BString, Object> options, BString key) {
if (!(options.getType() instanceof RecordType recordType)) {
public static BString getNameAnnotation(BMap<BString, Object> value, BString key) {
if (!(value.getType() instanceof RecordType recordType)) {
return key;
}
BMap<BString, Object> annotations = recordType.getAnnotations();
Expand Down

0 comments on commit ea9d9eb

Please sign in to comment.