import ballerina/io;
type Coord record {
float x;
float y;
};
public function main() returns error? {
json j = {x: 1.0, y: 2.0};
// Argument is a `typedesc` value.
// The static return type depends on the argument.
Coord c = check j.cloneWithType(Coord);
io:println(c.x);
// Argument defaulted from the context.
Coord d = check j.cloneWithType();
io:println(d.x);
return;
}
Converting to user-defined typeThe |
import ballerina/io;
type Coord record {
float x;
float y;
};
public function main() returns error? {
json j = {x: 1.0, y: 2.0};
Coord c = check j.cloneWithType(Coord);
Argument is a typedesc
value.
The static return type depends on the argument.
io:println(c.x);
Coord d = check j.cloneWithType();
Argument defaulted from the context.
io:println(d.x);
return;
}
bal run converting_to_user_defined_type.bal
1.0
1.0