ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.54k stars 733 forks source link

[Improvement]: Improvements to JSON to record conversion #42610

Open MaryamZi opened 3 weeks ago

MaryamZi commented 3 weeks ago

Description

$title.

Describe your problem(s)

For

{
    "a": 1, 
    "b": "str",
    "c": null
}

we generate

type NewRecord record {
    int a;
    string b;
    anydata c;
};

Describe your solution(s)

At the moment,

  1. when there are null values, the relevant field is generated as anydata, why not use json?
  2. the generated records are inclusive record typedescs, open by anydata. Can't we generate exclusive record typedescs with json as the rest descriptor instead?

This way, the generated record will also be a subtype of json.

type NewRecord record {|
    int a;
    string b;
    json c;
    json...;
|};

Related area

-> Other Area

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response