From a1c6d82198f73eab7f5b08e52b216d750d282c38 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Wed, 6 May 2020 10:49:08 +0200 Subject: [PATCH] https://github.com/danieleteti/delphimvcframework/issues/378 --- README.md | 13 +++++++++++-- samples/commons/BusinessObjectsU.pas | 13 +++++++++++++ samples/renders/RenderSampleControllerU.pas | 16 ++++++++++++++++ .../MVCFramework.Serializer.JsonDataObjects.pas | 16 ++++++++++++++-- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 59896a773..4141b4470 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,11 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma > We started the process of migrating our systems to micro services and are loving the DMVCFramework "DMVCFramework is definitely part of our lives right now". -- E. Costa +> "Thank you for the great framework! We are very happy with this!" -- Andreas + ## DMVCFramework Main Features - * Simple to use, check the ["Getting Started: 5 minutes guide"](https://danieleteti.gitbooks.io/delphimvcframework/content/chapter_getting_started.html) and you will be up and running in 5 minutes or less! (the guide is a bit outdated - a new book is being written by Daniele Teti. Let us know if you are interested in [DMVCFramework Handbook](https://leanpub.com/delphimvcframework)) + * Simple to use, check the ["Getting Started: 5 minutes guide"](https://danieleteti.gitbooks.io/delphimvcframework/content/chapter_getting_started.html) (it is quite old) and you will be up and running in 5 minutes or less! (the guide is a bit outdated - a new book is being written by Daniele Teti. Let us know if you are interested in [DMVCFramework Handbook](https://leanpub.com/delphimvcframework)) * [Project Roadmap](roadmap.md) is always public * More than 40 samples to learn all the features and be proficient and productive * Commercially supported by [bit Time Professionals](http://www.bittimeprofessionals.it) (training, consultancy, custom development etc.) @@ -61,7 +63,7 @@ Congratulations to Daniele Teti and all the staff for the excellent work!" -- Ma * Integrated REST Client * Works with Delphi 10 Seattle, Delphi 10.1 Berlin, Delphi 10.2 Tokyo, Delphi 10.3 Rio * Works on Linux (Delphi 10.2 Tokyo or better) - * Completely unit tested (more than 130 unit tests) + * Completely unit tested (more than 170 unit tests) * There is a sample for each functionality (check the [dmvcframework_(yourversion)_samples.zip](https://github.com/danieleteti/delphimvcframework/releases)) * Server side generated pages using [Mustache for Delphi](https://github.com/synopse/dmustache) or [TemplatePro](https://github.com/danieleteti/templatepro) * Specific trainings are available (email to `professionals@bittime.it` for a date and a place) @@ -459,6 +461,13 @@ end; Before it was not possible because you should add the `MVCListOf` attribute to the `TObjectList` type property. +- New! Added serialization support for (thanks to [dockerandy](https://github.com/dockerandy) for his initial work) + + - `TArray` + - `TArray` + - `TArray` + - `TArray` + - New! The **MVCAREntitiesGenerator** can optionally register all the generated entities also in the `ActiveRecordMappingRegistry` (Thanks to [Fabrizio Bitti](https://twitter.com/fabriziobitti) from [bit Time Software](http://www.bittime.it)) - New! Children objects lifecycle management in `TMVCActiveRecord` (methods `AddChildren` and `RemoveChildren`). Really useful to manage child objects such relations or derived properties and are safe in case of multiple addition of the same object as children. diff --git a/samples/commons/BusinessObjectsU.pas b/samples/commons/BusinessObjectsU.pas index 77ab2b5fb..7b2929adf 100644 --- a/samples/commons/BusinessObjectsU.pas +++ b/samples/commons/BusinessObjectsU.pas @@ -65,6 +65,19 @@ TPerson = class class function GetList(const aCount: Integer = 3): TObjectList; end; + TClassWithArrays = class + private + fArrayOfString: TArray; + fArrayOfInt: TArray; + fArrayOfInt64: TArray; + fArrayOfDouble: TArray; + public + property ArrayOfString: TArray read fArrayOfString write fArrayOfString; + property ArrayOfInt: TArray read fArrayOfInt write fArrayOfInt; + property ArrayOfInt64: TArray read fArrayOfInt64 write fArrayOfInt64; + property ArrayOfDouble: TArray read fArrayOfDouble write fArrayOfDouble; + end; + [MVCNameCase(ncLowerCase)] [MVCNameCase(ncLowerCase)] [MVCTable('nullables_test')] diff --git a/samples/renders/RenderSampleControllerU.pas b/samples/renders/RenderSampleControllerU.pas index 328fb8ef9..0249254ce 100644 --- a/samples/renders/RenderSampleControllerU.pas +++ b/samples/renders/RenderSampleControllerU.pas @@ -184,6 +184,10 @@ TRenderSampleController = class(TMVCController) [MVCPath('/nullables/many')] procedure GetManyNullableObjects; + // Arrays + [MVCHTTPMethod([httpGET])] + [MVCPath('/arrays')] + procedure GetClassWithArrays; end; implementation @@ -323,6 +327,18 @@ procedure TRenderSampleController.GetBinaryData(const filename: string); Render(TFileStream.Create(lFullFilePath, fmOpenRead or fmShareDenyNone)); end; +procedure TRenderSampleController.GetClassWithArrays; +var + lClass: TClassWithArrays; +begin + lClass := TClassWithArrays.Create; + lClass.ArrayOfString := ['one', 'two', 'three']; + lClass.ArrayOfInt := [1, 2, 3]; + lClass.ArrayOfInt64 := [high(Int64), high(Int64) - 1, high(Int64) - 2]; + lClass.ArrayOfDouble := [1234.5678, 2345.6789, 3456.78901]; + Render(lClass); +end; + procedure TRenderSampleController.GetCustomerByID_AsTObject(const ID: Integer); var Cust: TCustomer; diff --git a/sources/MVCFramework.Serializer.JsonDataObjects.pas b/sources/MVCFramework.Serializer.JsonDataObjects.pas index dcd858b38..d706719eb 100644 --- a/sources/MVCFramework.Serializer.JsonDataObjects.pas +++ b/sources/MVCFramework.Serializer.JsonDataObjects.pas @@ -832,19 +832,31 @@ function TMVCJsonDataObjectsSerializer.JsonArrayToArray(const AJsonArray: TJDOJs I: Integer; lStrArr: TArray; lIntArr: TArray; + lLongArr: TArray; + lDoubleArr: TArray; begin for I := 0 to Pred(AJsonArray.Count) do + begin case AJsonArray.types[0] of jdtString: lStrArr := lStrArr + [AJsonArray.Items[I].Value]; jdtInt: - lIntArr := lIntArr + [AJsonArray.Items[I].Value.ToInteger]; + lIntArr := lIntArr + [AJsonArray.Items[I].IntValue]; + jdtLong: + lLongArr := lLongArr + [AJsonArray.Items[I].LongValue]; + jdtFloat: + lDoubleArr := lDoubleArr + [AJsonArray.Items[I].FloatValue]; end; + end; if Length(lStrArr) > 0 then Result := TValue.From < TArray < string >> (lStrArr) + else if Length(lIntArr) > 0 then + Result := TValue.From < TArray < Integer >> (lIntArr) + else if Length(lLongArr) > 0 then + Result := TValue.From < TArray < Int64 >> (lLongArr) else - Result := TValue.From < TArray < Integer >> (lIntArr); + Result := TValue.From < TArray < Double >> (lDoubleArr); end; procedure TMVCJsonDataObjectsSerializer.JsonArrayToDataSet(const AJsonArray: TJDOJsonArray; const ADataSet: TDataSet;