Deserialize aggregate value
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}`);
Deserialize aggregate value using compile time symbol table