mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-11 18:08:15 +02:00
* Merging revisions r44776 from trunk:
------------------------------------------------------------------------ r44776 | michael | 2020-04-18 12:48:08 +0200 (Sat, 18 Apr 2020) | 1 line * Refactored ObjectToJSON so descendents have more control (bug ID 36803) ------------------------------------------------------------------------ git-svn-id: branches/fixes_3_2@46627 -
This commit is contained in:
parent
eef66ba7aa
commit
57313b637a
@ -54,6 +54,8 @@ Type
|
||||
function IsChildStored: boolean;
|
||||
function StreamChildren(AComp: TComponent): TJSONArray;
|
||||
protected
|
||||
Function GetPropertyList(aObject : TObject) : TPropInfoList; virtual;
|
||||
Procedure StreamProperties(aObject : TObject;aList : TPropInfoList; aParent : TJSONObject); virtual;
|
||||
function StreamClassProperty(Const AObject: TObject): TJSONData; virtual;
|
||||
Function StreamProperty(Const AObject : TObject; Const PropertyName : String) : TJSONData;
|
||||
Function StreamProperty(Const AObject : TObject; PropertyInfo : PPropInfo) : TJSONData;
|
||||
@ -757,12 +759,36 @@ begin
|
||||
Result:=(GetChildProperty<>'Children');
|
||||
end;
|
||||
|
||||
Function TJSONStreamer.GetPropertyList(aObject : TObject) : TPropInfoList;
|
||||
|
||||
begin
|
||||
result:=TPropInfoList.Create(AObject,tkProperties);
|
||||
end;
|
||||
|
||||
Procedure TJSONStreamer.StreamProperties(aObject : TObject;aList : TPropInfoList; aParent : TJSONObject);
|
||||
|
||||
Var
|
||||
I : Integer;
|
||||
PD : TJSONData;
|
||||
|
||||
begin
|
||||
For I:=0 to aList.Count-1 do
|
||||
begin
|
||||
PD:=StreamProperty(AObject,aList.Items[i]);
|
||||
If (PD<>Nil) then
|
||||
begin
|
||||
if jsoLowerPropertyNames in Options then
|
||||
aParent.Add(LowerCase(aList.Items[I]^.Name),PD)
|
||||
else
|
||||
aParent.Add(aList.Items[I]^.Name,PD);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TJSONStreamer.ObjectToJSON(Const AObject: TObject): TJSONObject;
|
||||
|
||||
Var
|
||||
PIL : TPropInfoList;
|
||||
PD : TJSONData;
|
||||
I : Integer;
|
||||
|
||||
begin
|
||||
Result:=Nil;
|
||||
@ -782,20 +808,12 @@ begin
|
||||
Result.Add('Objects', StreamTList(TList(AObject)))
|
||||
else
|
||||
begin
|
||||
PIL:=TPropInfoList.Create(AObject,tkProperties);
|
||||
PIL:=GetPropertyList(aObject);
|
||||
// TPropInfoList.Create(AObject,tkProperties);
|
||||
try
|
||||
For I:=0 to PIL.Count-1 do
|
||||
begin
|
||||
PD:=StreamProperty(AObject,PIL.Items[i]);
|
||||
If (PD<>Nil) then begin
|
||||
if jsoLowerPropertyNames in Options then
|
||||
Result.Add(LowerCase(PIL.Items[I]^.Name),PD)
|
||||
else
|
||||
Result.Add(PIL.Items[I]^.Name,PD);
|
||||
end;
|
||||
end;
|
||||
StreamProperties(aObject,PIL,Result);
|
||||
finally
|
||||
FReeAndNil(Pil);
|
||||
FreeAndNil(Pil);
|
||||
end;
|
||||
If (jsoStreamChildren in Options) and (AObject is TComponent) then
|
||||
Result.Add(ChildProperty,StreamChildren(TComponent(AObject)));
|
||||
|
Loading…
Reference in New Issue
Block a user