One feature that comparable libraries such as serde for Rust offer, is the ability to flatten inner objects. This would be a nice addition for as-json.
From usage perspective, this could look like this:
@json
class MyInnerClass {
first: string;
second: i32;
}
@json
class MyOuterClass {
otherProperty: f64;
@flatten
inner: MyInnerClass;
}
Serializing an instance of MyOuterClass would result in JSON similar to this:
One feature that comparable libraries such as serde for Rust offer, is the ability to flatten inner objects. This would be a nice addition for as-json.
From usage perspective, this could look like this:
Serializing an instance of
MyOuterClass
would result in JSON similar to this:The ability to flatten subproperties also helps to mitigate the shortcoming of AssemblyScript, that there are no nullable primitives as of today.
With flattening support this could be achieved like the following:
Without flattening, it is impossible to not propagate the helper properties to the outside world.