Closed sallypmt closed 4 years ago
Push
The library (currently) does not support serialization of (generic) collections. It does support serialization of dynamic arrays though.
So you could add a serializable property of type TArray. In the getter, it could return TObjectList.ToArray. In the setter, it could add the array to the list.
It's fine. I understand. It's okay. Your code works great.
How to serialize TObjectList using TgoBsonSerializer? I got it in my way
Type TVehicle = class;
MyVehicles: TObjectList<TVehicle>;
procedure SerializeVehicles(out aResult: String);
var
V: TVehicle;
CurrentItem: String;
const MACRO = '$NEXTITEM'
begin
aResult := '{"Result": [' + MACRO;
try
if MyVehicles.Count = 0 then
aResult := '{"Result": []}';
for V in MyVehicles do
begin
TGoBsonSerializer.Serialize<TRetorno>(V, CurrentItem);
aResult := StringReplace(aResult, MACRO, CurrentItem + ',' + MACRO, []);
end;
finally
aResult := StringReplace(aResult, ',' + MACRO, ']}');
end;
end;
q. How to serialize TObjectList using TgoBsonSerializer?