#1 2022-05-05 12:47:26

AntonE
Member
Registered: 2012-02-03
Posts: 74

mORMot2 TObjectList RegisterClassForJSON

As TObjectList is not a TPersistentClass it cannot be registered for JSON via Rtti.RegisterClass and TJSONSerializer.RegisterClassForJSON is not available anymore.
How can I register it as I use it extensively in mormot1 code migrated to mormot2

Thanks
AntonE

Offline

#2 2022-05-05 16:02:19

tbo
Member
Registered: 2015-04-20
Posts: 353

Re: mORMot2 TObjectList RegisterClassForJSON

I'm not sure I understood you correctly, but this works without any registration:

var
  item: TItem;  // TItem = class(TObject)
  list: TObjectList;
begin
  list := TObjectList.Create;
  try
    list.Add(TItem.Create('value1'));
    list.Add(TItem.Create('value2'));
    ObjectToJsonFile(list, '_listData.json');
  finally
    list.Free;
  end;

With best regards
Thomas

Offline

#3 2022-05-07 15:17:37

AntonE
Member
Registered: 2012-02-03
Posts: 74

Re: mORMot2 TObjectList RegisterClassForJSON

I have TJSONSerializer.RegisterClassForJSON(TObjectList) on Client app (XE4/mormot1) but had to comment that line out on server (D11/mormot2) as described in OP.
I pass the objectlist via Intertfaced based service method,e.g.

function CalList(var Lst:TObjectList):Boolean; 

Regards
AntonE

Last edited by AntonE (2022-05-07 15:19:11)

Offline

Board footer

Powered by FluxBB