diff --git a/Generator GUI/JSON_PAS.res b/Generator GUI/JSON_PAS.res index 43d6a84..77d9252 100644 Binary files a/Generator GUI/JSON_PAS.res and b/Generator GUI/JSON_PAS.res differ diff --git a/Lib/Pkg.Json.DTO.pas b/Lib/Pkg.Json.DTO.pas index 68ed384..4b41f8a 100644 --- a/Lib/Pkg.Json.DTO.pas +++ b/Lib/Pkg.Json.DTO.pas @@ -27,6 +27,11 @@ TJsonDTO = class(TArrayMapper) property AsJson: string read GetAsJson write SetAsJson; end; + GenericListReflectAttribute = class(JsonReflectAttribute) + public + constructor Create; + end; + implementation uses @@ -188,5 +193,30 @@ function TArrayMapper.ObjectList(var aList: TObjectList; aSource: TArray; + RttiProperty: TRttiProperty; +begin + RttiProperty := ctx.GetType(Data.ClassInfo).GetProperty(Copy(Field, 2, MAXINT)); + List := TList(RttiProperty.GetValue(Data).AsObject); + Result := TListOfObjects(List.List); + SetLength(Result, List.Count); +end; + +constructor GenericListReflectAttribute.Create; +begin + inherited Create(ctObjects, rtObjects, TGenericListFieldInterceptor, nil, false); +end; + end. \ No newline at end of file diff --git a/Lib/Pkg.Json.StubField.pas b/Lib/Pkg.Json.StubField.pas index 37dc732..726c143 100644 --- a/Lib/Pkg.Json.StubField.pas +++ b/Lib/Pkg.Json.StubField.pas @@ -187,7 +187,7 @@ function TStubClass.GetImplementationPart: string; Lines.Add(''); Lines.AddFormat('function %s.Get%s: TObjectList<%s>;', [Name, StubField.PropertyName, StubArrayField.TypeAsString]); Lines.Add('begin'); - Lines.AddFormat(' Result := ObjectList<%s>(%s, %sArray);', [StubArrayField.TypeAsString, StubField.FieldName, StubField.FieldName]); + Lines.AddFormat(' Result := ObjectList<%s>(%s, %sArray);', [StubArrayField.TypeAsString, StubField.FieldName, StubField.FieldName]); Lines.Add('end;'); end; @@ -249,8 +249,9 @@ Lines.Add(Name + ' = class' + IfThen(BaseClass = '', '', '(' + BaseClass + ' begin StubArrayField := StubField as TStubArrayField; Lines.Add(' ' + StubField.NameAttribute); - Lines.AddFormat(' %sArray: TArray<%s>;', [StubField.FieldName, StubField.TypeAsString]); Lines.Add(' [JSONMarshalled(False)]'); + Lines.AddFormat(' %sArray: TArray<%s>;', [StubField.FieldName, StubField.TypeAsString]); + Lines.Add(' [GenericListReflect]'); Lines.AddFormat(' %s: TObjectList<%s>;', [StubField.FieldName, StubArrayField.TypeAsString]); end else