diff --git a/Source/Neon.Core.Persistence.JSON.pas b/Source/Neon.Core.Persistence.JSON.pas index ec94c1b..af230ca 100644 --- a/Source/Neon.Core.Persistence.JSON.pas +++ b/Source/Neon.Core.Persistence.JSON.pas @@ -211,7 +211,12 @@ TNeonDeserializerJSON = class(TNeonBase, IDeserializerContext) /// /// Decides to whether or not to create the object and assigning it to the reference /// - function ManageReference(const AParam: TNeonDeserializerParam; const AData: TValue): TValue; + function ReadReference(const AParam: TNeonDeserializerParam; const AData: TValue): TValue; + + /// + /// Decides to whether or not to create the object and assigning it to the reference + /// + function ManageInstance(AValue: TJSONValue; const AData: TValue; ANeonObject: TNeonRttiObject): TValue; private /// /// reader for string types @@ -1312,6 +1317,7 @@ function TNeonDeserializerJSON.ReadDataMember(const AParam: TNeonDeserializerPar const AData: TValue; ACustomProcess: Boolean): TValue; var LCustom: TCustomSerializer; + LValue: TValue; begin if ACustomProcess then begin @@ -1319,7 +1325,8 @@ function TNeonDeserializerJSON.ReadDataMember(const AParam: TNeonDeserializerPar LCustom := FConfig.Serializers.GetSerializer(AParam.RttiType.Handle); if Assigned(LCustom) then begin - Result := LCustom.Deserialize(AParam.JSONValue, AData, AParam.NeonObject, Self); + LValue := ManageInstance(AParam.JSONValue, AData, AParam.NeonObject); + Result := LCustom.Deserialize(AParam.JSONValue, LValue, AParam.NeonObject, Self); Exit(Result); end; end; @@ -1348,7 +1355,7 @@ function TNeonDeserializerJSON.ReadDataMember(const AParam: TNeonDeserializerPar tkClass: begin if TJSONUtils.HasValues(AParam.JSONValue) then - Result := ManageReference(AParam, AData); + Result := ReadReference(AParam, AData); end; tkInterface: Result := ReadInterface(AParam, AData); @@ -1873,18 +1880,26 @@ function TNeonDeserializerJSON.JSONToTValue(AJSON: TJSONValue; AType: TRttiType; Result := ReadDataMember(AJSON, AType, AData); end; -function TNeonDeserializerJSON.ManageReference(const AParam: TNeonDeserializerParam; const AData: TValue): TValue; +function TNeonDeserializerJSON.ManageInstance(AValue: TJSONValue; const AData: TValue; ANeonObject: TNeonRttiObject): TValue; var LType: TRttiType; - LValue: TValue; begin - LValue := AData; - if (AData.AsObject = nil) and - (FConfig.AutoCreate or AParam.NeonObject.NeonAutoCreate) then + Result := AData; + if (AData.IsObject) and (AData.AsObject = nil) and + TJSONUtils.HasValues(AValue) and + (FConfig.AutoCreate or ANeonObject.NeonAutoCreate) then begin LType := TRttiUtils.Context.GetType(AData.TypeInfo); - LValue := TRttiUtils.CreateInstance(LType); + Result := TRttiUtils.CreateInstance(LType); end; +end; + +function TNeonDeserializerJSON.ReadReference(const AParam: + TNeonDeserializerParam; const AData: TValue): TValue; +var + LValue: TValue; +begin + LValue := ManageInstance(AParam.JSONValue, AData, AParam.NeonObject); if ReadEnumerableMap(AParam, LValue) then Result := LValue diff --git a/Source/Neon.Core.Persistence.pas b/Source/Neon.Core.Persistence.pas index c694d0b..cd3e180 100644 --- a/Source/Neon.Core.Persistence.pas +++ b/Source/Neon.Core.Persistence.pas @@ -983,7 +983,7 @@ function TNeonRttiMembers.NewMember(AMember: TRttiMember): TNeonRttiMember; function TNeonRttiObject.AsRttiType: TRttiType; begin - // Trhows an exception if not (is better than returnig nil and have to check outside) + // Throws an exception if not (is better than returnig nil and have to check outside) Result := FRttiObject as TRttiType; end; diff --git a/Tests/Neon.Tests.Framework.dproj b/Tests/Neon.Tests.Framework.dproj index 1b64fa8..b7175a2 100644 --- a/Tests/Neon.Tests.Framework.dproj +++ b/Tests/Neon.Tests.Framework.dproj @@ -39,6 +39,12 @@ Base true + + true + Cfg_2 + true + true + .\$(Platform)\$(Config) .\Bin @@ -61,8 +67,9 @@ DBXSqliteDriver;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;tethering;svnui;JvGlobus;FireDACADSDriver;SMCmpntRX102;uniGUI25Chart;frxe25;JvPluginSystem;DBXMSSQLDriver;JvMM;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;JvBands;vcldb;bindcompfmx;svn;JvJans;DBXOracleDriver;unidac250;JvNet;inetdb;JvAppFrm;RaizeComponentsVcl;FmxTeeUI;emsedge;JvDotNetCtrls;fmx;fmxdae;frxDB25;RaizeComponentsVclDb;JvWizards;frxTee25;FireDACDBXDriver;dbexpress;IndyCore;vclx;InspexVclDb;JvPageComps;dsnap;DataSnapCommon;WiRLRunTime;JvDB;DataSnapConnectors;uniGUI25m;VCLRESTComponents;JclDeveloperTools;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;vquery250;JvCmp;JvHMI;FireDACCommonODBC;DataSnapClient;IndyIPCommon;bindcompdbx;JvCustom;vcl;IndyIPServer;DBXSybaseASEDriver;JvXPCtrls;dac250;IndySystem;PngComponents;FireDACDb2Driver;dsnapcon;madExcept_;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;madBasic_;TeeDB;Jcl;JvCore;emshosting;JvCrypt;FireDACPgDriver;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;DbxCommonDriver;JvDlgs;JvRuntimeDesign;JvManagedThreads;Tee;DataSnapServer;xmlrtl;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;unidacfmx250;DbxClientDriver;dacvcl250;DBXSybaseASADriver;JvTimeFramework;CustomIPTransport;vcldsnap;TechnoFramework;JvSystem;JvStdCtrls;frx25;CodeSiteExpressPkg;madDisAsm_;bindcomp;appanalytics;DBXInformixDriver;NativeExcelTokyo;IndyIPClient;bindcompvcl;SynEdit_R;TeeUI;JvDocking;dbxcds;VclSmp;unidacvcl250;adortl;FireDACODBCDriver;JvPascalInterpreter;JclVcl;DataSnapIndy10ServerTransport;dacfmx250;InspexVcl;uniGUI25VCL;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;JvControls;JvPrintPreview;JclContainers;uSynEdit_R2021;DataSnapServerMidas;$(DCC_UsePackage) Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) Debug - CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= + (None) 1033 + none DBXSqliteDriver;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;tethering;FireDACADSDriver;uniGUI25Chart;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;DBXOracleDriver;inetdb;RaizeComponentsVcl;FmxTeeUI;emsedge;fmx;fmxdae;RaizeComponentsVclDb;FireDACDBXDriver;dbexpress;IndyCore;vclx;dsnap;DataSnapCommon;DataSnapConnectors;uniGUI25m;VCLRESTComponents;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;DataSnapClient;IndyIPCommon;bindcompdbx;vcl;IndyIPServer;DBXSybaseASEDriver;IndySystem;PngComponents;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;emshosting;FireDACPgDriver;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;DbxCommonDriver;Tee;DataSnapServer;xmlrtl;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;SynEdit_R;TeeUI;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;uniGUI25VCL;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;uSynEdit_R2021;DataSnapServerMidas;$(DCC_UsePackage) @@ -87,6 +94,11 @@ 0 0 + + 1033 + (None) + none + MainSource @@ -132,6 +144,7 @@ Microsoft Office 2000 Sample Automation Server Wrapper Components Microsoft Office XP Sample Automation Server Wrapper Components + File C:\WINDOWS\system32\dclSvComV8D28.bpl not found