The OpenD Programming Language

serializeJSON

Serializes an object to a JSONValue. To make this work, use serializable UDA on any fields that you want to be serializable. Automatically maps marked fields to corresponding JSON types. Any field not marked with serializable is not serialized.

@safe
serializeJSON
(
T
)
(
auto ref T obj
)

Examples

struct Test
{
    @serializable int test = 43;
    @serializable string other = "Hello, world";

    @serializable int foo() { return inaccessible; }
    @serializable void foo(int val) { inaccessible = val; }
private:
    int inaccessible = 32;
}

auto val = serializeJSON(Test());
assert(val["test"].get!int == 43);
assert(val["other"].get!string == "Hello, world");
assert(val["foo"].get!int == 32);

Meta