Hi, Wagner
With Datasnap rest server, to Deserialize "TObject", i'm using the fallowing code:
function TServerMethod.SaveUpdate(ClientJson: TJsonValue): Boolean;
var
Obj: TObject;
begin
Obj := JsonX.FromJson(ClientJson, TObject);
end;
How to Deserialize "TObjectList<TObject>"?
function TServerMethod.SaveUpdateList(ClientJson: TJsonValue): TJsonValue;
var
ObjList: TObjectList<TObject>;
begin
ObjList := JsonX.FromJson(ClientJson, TObjectList<TObject>); //How to do something like this?
end;
Thanks
Have you tried using TList<TObject>? What is the error your get?
Hi, Wagner
If i do something like this:
...
var
fDeserializer: TDataSnapJsonDeserializer;
ObjList: TList<TObject>;
begin
fDeserializer := TDataSnapJsonDeserializer.Create;
ObjList := FDeserializer.FromJson(ClientJson, TList<TObject>); //[dcc32 Error] XXXXXX.pas(113): E2010 Incompatible types: 'System.Generics.Collections.TList<System.TObject>' and 'TObject'
end;
but if i call generic version of the method:
...
ObjList := FDeserializer.FromJson<TList<TObject>>(ClientJson);
...
Work as expected
Thanks
non-generic FromJson returns a TObject. You must cast the result to the type you want, otherwise of course the Delphi compiler will complain.