The OpenD Programming Language

deserializeValue

Deserialize aggregate value using compile time symbol table

  1. IonException deserializeValue(IonDescribedValue data, T value, RuntimeSymbolTable table, const(uint)[] tableIndex, Annotations annotations_)
    template deserializeValue(string[] symbolTable, TableKind tableKind)
    @safe pure
    deserializeValue
    (
    T
    Annotations...
    )
    (,
    return scope ref T value
    ,
    scope RuntimeSymbolTable table
    ,
    scope const(uint)[] tableIndex
    ,
    scope Annotations annotations_
    )
    if (
    !isFirstOrderSerdeType!T &&
    &&
    Annotations.length <= 1
    )
  2. alias deserializeValue = .deserializeValue_

Members

Aliases

deserializeValue
alias deserializeValue = .deserializeValue_

Functions

deserializeValue
IonException deserializeValue(IonDescribedValue data, T value, RuntimeSymbolTable table, const(uint)[] tableIndex, Annotations annotations_)

Deserialize aggregate value

Examples

import mir.deser.json;
import std.uuid;

static struct S
{
    @serdeScoped
    @serdeProxy!string
    UUID id;
}
assert(`{"id":"8AB3060E-2cba-4f23-b74c-b52db3bdfb46"}`.deserializeJson!S.id
            == UUID("8AB3060E-2cba-4f23-b74c-b52db3bdfb46"));

Mir types

import mir.bignum.integer;
import mir.date;
import mir.deser.json: deserializeJson;
assert(`"2021-04-24"`.deserializeJson!Date == Date(2021, 4, 24));
assert(`123`.deserializeJson!(BigInt!2) == BigInt!2(123));

Mir types

static struct S
{
    @serdeIgnoreIn
    bool set;
    @serdeScoped
    @property auto a(scope int[] a) @safe
    {
        static immutable d = [1, 2, 3];
        set = a == d;
    }
}
import mir.deser.json: deserializeJson;
auto s = `{"a":[1, 2, 3]}`.deserializeJson!S;
assert(s.set);
enum Kind { request, cancel }

@serdeRealOrderedIn
static struct S
{
    Kind kind;

    @serdeIgnoreInIfAggregate!((ref a) => a.kind == Kind.cancel)
    @serdeIgnoreOutIfAggregate!((ref a) => a.kind == Kind.cancel)
    int number;
}

import mir.deser.json: deserializeJson;
import mir.ser.json: serializeJson;
assert(`{"number":3, "kind":"cancel"}`.deserializeJson!S.kind == Kind.cancel);
assert(`{"number":3, "kind":"cancel"}`.deserializeJson!S.number == 0);
assert(`{"number":3, "kind":"request"}`.deserializeJson!S.number == 3);
assert(`{"kind":"request","number":3}`.deserializeJson!S.number == 3);
assert(S(Kind.cancel, 4).serializeJson == `{"kind":"cancel"}`);
assert(S(Kind.request, 4).serializeJson == `{"kind":"request","number":4}`);
enum Kind { request, cancel }

@serdeRealOrderedIn
static struct S
{
    Kind kind;

    @serdeIgnoreIfAggregate!((ref a) => a.kind == Kind.cancel)
    int number;
}

import mir.deser.json: deserializeJson;
import mir.ser.json: serializeJson;
assert(`{"kind":"cancel"}`.deserializeJson!S.kind == Kind.cancel);
assert(`{"kind":"cancel","number":3}`.deserializeJson!S.number == 0); // ignores number
assert(`{"kind":"request","number":3}`.deserializeJson!S.number == 3);
assert(S(Kind.cancel, 4).serializeJson == `{"kind":"cancel"}`);
assert(S(Kind.request, 4).serializeJson == `{"kind":"request","number":4}`);

Meta