ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

union array as expected type generate invalid result for record to xml conversion with `toXml()` function #6689

Open prakanth97 opened 4 months ago

prakanth97 commented 4 months ago

Description:

@xmldata:Namespace {prefix: "wsa", uri: "http://www.w3.org/2005/08/addressing"}
type Wsa_ReplyTo record {
    @xmldata:Namespace {prefix: "wsa", uri: "http://www.w3.org/2005/08/addressing"}
    string Address;
};

@xmldata:Namespace{prefix: "htng", uri: "http://htng.org/PWSWG/2007/02/AsyncHeaders"}
type Htng_ReplyTo record {
    @xmldata:Namespace {prefix: "htng", uri: "http://htng.org/PWSWG/2007/02/AsyncHeaders"}
    string Address;
};

@xmldata:Name {value: "soap"}
type Soap record {
    (Htng_ReplyTo|Wsa_ReplyTo)[] ReplyTo;
};

public function main() returns error? {
    Soap j = {
        ReplyTo: [
            <Wsa_ReplyTo>{Address: "http://www.w3.org/2005/08/addressing/role/anonymous"},
            <Htng_ReplyTo>{Address: "http://demo5199745.mockable.io/post/"}
        ]
    };

    xml val = check xmldata:toXml(j);
    io:println(val);
}

Output is wrong:

<soap>
        <ReplyTo>{"Address":"http://www.w3.org/2005/08/addressing/role/anonymous"}</ReplyTo>
        <ReplyTo>{"Address":"http://demo5199745.mockable.io/post/"}</ReplyTo>
</soap>

Steps to reproduce: 0.1.1

Affected Versions:

OS, DB, other environment details and versions:

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

prakanth97 commented 4 months ago

Related https://github.com/ballerina-platform/ballerina-library/issues/6596