Skip to content

Commit

Permalink
Fix toJson not using the Name annotation with tables
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryamZi committed Nov 12, 2024
1 parent 4156d57 commit 4bf064c
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BStream;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.api.values.BTable;
import io.ballerina.runtime.api.values.BTypedesc;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -121,6 +122,17 @@ public static Object toJson(Object value, Set<Object> visitedValues) {
return jsonObject;
}

if (value instanceof BTable tableValue) {
int length = tableValue.size();
Object[] convertedValues = new Object[length];

int index = 0;
for (Object tableMember : tableValue.values()) {
convertedValues[index++] = toJson(tableMember, visitedValues);
}
return ValueCreator.createArrayValue(convertedValues, PredefinedTypes.TYPE_JSON_ARRAY);
}

return JsonUtils.convertToJson(value);
}

Expand Down

0 comments on commit 4bf064c

Please sign in to comment.