From a66c7e4f9b4644225bbe824e86b42054db240829 Mon Sep 17 00:00:00 2001 From: Jens Borrisholt Date: Fri, 31 Jul 2020 07:46:59 +0200 Subject: [PATCH] Bug Fix for serialization --- Generator GUI/JSON_PAS.res | Bin 5124 -> 6008 bytes Lib/Pkg.Json.DTO.pas | 30 ++++++++++++++++++++++++++++++ Lib/Pkg.Json.StubField.pas | 5 +++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Generator GUI/JSON_PAS.res b/Generator GUI/JSON_PAS.res index 43d6a84394928ca7141e3c566cc074e98e164a37..77d9252b8fa23904352504e098d8805603b8c991 100644 GIT binary patch delta 849 zcmaJR?ntuYCd3!*YG>xnd-LXA{EdFV>%+G{58n4i0H>(YDtWFP%`nSR(wNAq zc}WN#LFTD*;>;QSG#EUjd+&b5z29#tS{FFz10-8mpA_bci6*oX3o^FDO3tpP7h8dV zD~ocTE6F#2tkjZ}(J-BV_iS8j^bJ}MBu-LFhmbVyBdA*p!Bw8FUIsqGBBoheHv;49 ztXklRfl)8~$+z1k@fpKA4tL#miHZKBR_);S0<}T^Cbi5((#rFm5h*W|a78s&*3ruO z(8@io1DtqiP2uOUZtE^>)%^Q}IWCoE*zG(RdK+mKogyXPsCtS~%)U-^W&(cSK#JHD zYf%p-grg8XkH1bXk|5|vF;+e0j+U5F^~j0AzNC5CbP1xdYbMno%+QrNbr_vfg7rrH zY4Wa+&QUMvS~L|Q)CsXEb)B)XQX1{ZmR_CTudUsCx~dO4(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