De-serializing with X-SuperObject

117 Views Asked by At

I have such classes:

type
  TBmItem = class
    [ALIAS('I')]  Id:       UInt32;
    [ALIAS('C')]  Caption:  string;
  end;

  TBmList = TList<TBmItem>;
    
  TBmItems = class
    [ALIAS('Bm')] Bookmarks:  TBmList;
  end;
    
  TAccItem = class
  public
    [ALIAS('I')]  Id:         UInt32;
    [ALIAS('Bm')] Bookmarks:  TBmList;
  end;

var Acc: TAccItem;
// fill the Acc variable
var sJson := Acc.ToJSON;

Now I have this JSON in sJson string:

{
    "I":0,
    "Bm":[
        {"I":0, "C":"0"},
        {"I":1, "C":"1"},
        {"I":2, "C":"2"}
    ]
}

Now I need the "Bm" part of the JSON:

var X := SO(sJson);
var sBm := X.A['Bm'].AsJSON;
var sBmFull := '{"Bm":' + X.A['Bm'].AsJSON + '}';
var BmItems := TBmItems.FromJSON(sBmFull);
var BmList := TBmList.FromJSON(?);

With sBm I can't de-serialize the BmItems variable and I need to manual prepare the sBmFull variable.

The sBm variable is:

[
    {"I":0, "C":"0"},
    {"I":1, "C":"1"},
    {"I":2, "C":"2"}
]

Questions:

  1. Is it possible to get sBmFull from the X without manual additions?
  2. After changing the BmItems how to set it back to the X variable?
  3. Is it possible using current X variable to de-serialize the BmList variable, what I should to do?

Update: Q2 is resolved using this code:

var X2 := SO(BmItems.ToJSON);
X.A['Bm'] := X2.A['Bm'];
0

There are 0 best solutions below