mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
This commit is contained in:
parent
f853b362b3
commit
08f01e6633
@ -328,6 +328,8 @@ end;
|
||||
|
||||
- Fixed! [issue363](https://github.com/danieleteti/delphimvcframework/issues/363)
|
||||
|
||||
- Fixed! [issue366](https://github.com/danieleteti/delphimvcframework/issues/366)
|
||||
|
||||
- **Breaking Change!** In `MVCActiveRecord` attribute `MVCPrimaryKey` has been removed and merged with `MVCTableField`, so now `TMVCActiveRecordFieldOption` is a set of `foPrimaryKey`, `foAutoGenerated`, `foTransient` (check `activerecord_showcase.dproj` sample).
|
||||
|
||||
- **Breaking Change!** Middleware `OnAfterControllerAction` are now invoked in the same order of `OnBeforeControllerAction` (previously were invoked in reversed order).
|
||||
|
@ -447,11 +447,11 @@ type
|
||||
procedure SetItems(const Key: string; const Value: TObject);
|
||||
protected
|
||||
fDict: TObjectDictionary<string, TObject>;
|
||||
{
|
||||
{
|
||||
TMVCSerializationAction = reference to procedure(const AObject: TObject; const Links: IMVCLinks);
|
||||
TMVCDataSetSerializationAction = reference to procedure(const ADataSet: TDataset; const Links: IMVCLinks);
|
||||
|
||||
}
|
||||
}
|
||||
public
|
||||
constructor Create(const OwnsValues: Boolean = True); overload; virtual;
|
||||
constructor Create(const aKey: string; const Value: TObject; const OwnsValues: Boolean = True); overload; virtual;
|
||||
@ -648,6 +648,8 @@ type
|
||||
VPassword: string; var VHandled: Boolean);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
|
@ -45,30 +45,31 @@ type
|
||||
TDataSetHelper = class helper for TDataSet
|
||||
public
|
||||
procedure LoadFromTValue(const Value: TValue; const aNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase);
|
||||
function AsJSONArray: string;
|
||||
function AsJDOJSONArray: TJDOJsonArray;
|
||||
function AsJSONArray(FieldNameCase: TMVCNameCase = ncLowerCase): string;
|
||||
function AsJDOJSONArray(FieldNameCase: TMVCNameCase = ncLowerCase): TJDOJsonArray;
|
||||
function AsJSONArrayOfValues: TJDOJsonArray;
|
||||
function AsJSONArrayString: string; deprecated 'Use AsJSONArray';
|
||||
function AsJSONObject(AFieldNamePolicy: TFieldNamePolicy = fpLowerCase): string;
|
||||
function AsJSONObject(FieldNameCase: TMVCNameCase = ncLowerCase; const IgnoredFields: TArray<string> = []): string;
|
||||
function AsJSONObjectString: string; deprecated 'Use AsJSONObject';
|
||||
procedure LoadFromJSONObject(AJSONObject: TJSONObject; AFieldNamePolicy: TFieldNamePolicy = fpLowerCase); overload;
|
||||
procedure LoadFromJSONObject(AJSONObject: TJSONObject; AIgnoredFields: TArray<string>;
|
||||
AFieldNamePolicy: TFieldNamePolicy = fpLowerCase); overload;
|
||||
procedure LoadFromJSONObject(const JSONObject: TJSONObject; const FieldNameCase: TMVCNameCase); overload;
|
||||
procedure LoadFromJSONObject(const JSONObject: TJSONObject; const AIgnoredFields: TArray<string> = [];
|
||||
const FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
|
||||
procedure LoadFromJSONArray(AJSONArray: string;
|
||||
AFieldNamePolicy: TFieldNamePolicy = TFieldNamePolicy.fpLowerCase); overload;
|
||||
FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
|
||||
procedure LoadFromJSONArrayString(AJSONArrayString: string; AIgnoredFields: TArray<string>;
|
||||
AFieldNamePolicy: TFieldNamePolicy = TFieldNamePolicy.fpLowerCase); overload;
|
||||
FieldNameCase: TMVCNameCase = ncLowerCase); overload;
|
||||
procedure LoadFromJSONArrayString(AJSONArrayString: string;
|
||||
AFieldNamePolicy: TFieldNamePolicy = TFieldNamePolicy.fpLowerCase); overload;
|
||||
FieldNameCase: TMVCNameCase = ncLowerCase); overload;
|
||||
procedure LoadFromJSONArray(AJSONArray: TJSONArray;
|
||||
AFieldNamePolicy: TFieldNamePolicy = TFieldNamePolicy.fpLowerCase); overload;
|
||||
FieldNameCase: TMVCNameCase = ncLowerCase); overload;
|
||||
procedure LoadFromJSONObjectString(AJSONObjectString: string); overload;
|
||||
procedure LoadFromJSONObjectString(AJSONObjectString: string; AIgnoredFields: TArray<string>); overload;
|
||||
procedure LoadFromJSONObjectString(const JSONObjectString: string; const IgnoredFields: TArray<string>;
|
||||
const FieldNameCase: TMVCNameCase = ncLowerCase); overload;
|
||||
procedure LoadJSONArrayFromJSONObjectProperty(const AJSONObjectString: string; const aPropertyName: string;
|
||||
const AFieldNamePolicy: TFieldNamePolicy = TFieldNamePolicy.fpLowerCase);
|
||||
const FieldNameCase: TMVCNameCase = ncLowerCase);
|
||||
procedure AppendFromJSONArrayString(AJSONArrayString: string); overload;
|
||||
procedure AppendFromJSONArrayString(AJSONArrayString: string; AIgnoredFields: TArray<string>;
|
||||
AFieldNamePolicy: TFieldNamePolicy = TFieldNamePolicy.fpLowerCase); overload;
|
||||
FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
|
||||
function AsObjectList<T: class, constructor>(CloseAfterScroll: boolean = false; OwnsObjects: boolean = true)
|
||||
: TObjectList<T>;
|
||||
function AsObject<T: class, constructor>(CloseAfterScroll: boolean = false): T;
|
||||
@ -188,20 +189,20 @@ begin
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadJSONArrayFromJSONObjectProperty(const AJSONObjectString: string;
|
||||
const aPropertyName: string; const AFieldNamePolicy: TFieldNamePolicy);
|
||||
const aPropertyName: string; const FieldNameCase: TMVCNameCase);
|
||||
var
|
||||
lJson: TJSONObject;
|
||||
begin
|
||||
lJson := TJSONObject.Create;
|
||||
try
|
||||
lJson.FromJSON(AJSONObjectString);
|
||||
LoadFromJSONArray(lJson.A[aPropertyName], AFieldNamePolicy);
|
||||
LoadFromJSONArray(lJson.A[aPropertyName], FieldNameCase);
|
||||
finally
|
||||
lJson.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TDataSetHelper.AsJDOJSONArray: TJDOJsonArray;
|
||||
function TDataSetHelper.AsJDOJSONArray(FieldNameCase: TMVCNameCase = ncLowerCase): TJDOJsonArray;
|
||||
var
|
||||
lSerializer: TMVCJsonDataObjectsSerializer;
|
||||
begin
|
||||
@ -211,7 +212,7 @@ begin
|
||||
begin
|
||||
lSerializer := TMVCJsonDataObjectsSerializer.Create;
|
||||
try
|
||||
lSerializer.DataSetToJsonArray(Self, Result, ncLowerCase, []);
|
||||
lSerializer.DataSetToJsonArray(Self, Result, FieldNameCase, []);
|
||||
finally
|
||||
lSerializer.Free;
|
||||
end;
|
||||
@ -243,7 +244,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TDataSetHelper.AsJSONArray: string;
|
||||
function TDataSetHelper.AsJSONArray(FieldNameCase: TMVCNameCase = ncLowerCase): string;
|
||||
var
|
||||
lSerializer: IMVCSerializer;
|
||||
begin
|
||||
@ -251,7 +252,7 @@ begin
|
||||
if not Eof then
|
||||
begin
|
||||
lSerializer := TMVCJsonDataObjectsSerializer.Create;
|
||||
Result := lSerializer.SerializeDataSet(Self, [], ncLowerCase);
|
||||
Result := lSerializer.SerializeDataSet(Self, [], FieldNameCase);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -260,18 +261,17 @@ begin
|
||||
Result := AsJSONArray;
|
||||
end;
|
||||
|
||||
function TDataSetHelper.AsJSONObject(AFieldNamePolicy: TFieldNamePolicy): string;
|
||||
function TDataSetHelper.AsJSONObject(FieldNameCase: TMVCNameCase; const IgnoredFields: TArray<string>): string;
|
||||
var
|
||||
lSerializer: IMVCSerializer;
|
||||
begin
|
||||
lSerializer := TMVCJsonDataObjectsSerializer.Create;
|
||||
Result := lSerializer.SerializeDataSetRecord(Self, [], ncAsIs);
|
||||
// Mapper.DataSetToJSONObject(Self, JObj, false);
|
||||
Result := lSerializer.SerializeDataSetRecord(Self, TMVCIgnoredList(IgnoredFields), FieldNameCase);
|
||||
end;
|
||||
|
||||
function TDataSetHelper.AsJSONObjectString: string;
|
||||
begin
|
||||
Result := AsJSONObject(fpLowerCase);
|
||||
Result := AsJSONObject(ncLowerCase);
|
||||
end;
|
||||
|
||||
function TDataSetHelper.AsObject<T>(CloseAfterScroll: boolean): T;
|
||||
@ -307,26 +307,26 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadFromJSONArray(AJSONArray: string; AFieldNamePolicy: TFieldNamePolicy);
|
||||
procedure TDataSetHelper.LoadFromJSONArray(AJSONArray: string; FieldNameCase: TMVCNameCase);
|
||||
var
|
||||
lSerializer: IMVCSerializer;
|
||||
begin
|
||||
Self.DisableControls;
|
||||
try
|
||||
lSerializer := TMVCJsonDataObjectsSerializer.Create;
|
||||
lSerializer.DeserializeDataSet(AJSONArray, Self, nil, ncAsIs);
|
||||
lSerializer.DeserializeDataSet(AJSONArray, Self, nil, FieldNameCase);
|
||||
finally
|
||||
Self.EnableControls;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadFromJSONArrayString(AJSONArrayString: string; AIgnoredFields: TArray<string>;
|
||||
AFieldNamePolicy: TFieldNamePolicy);
|
||||
FieldNameCase: TMVCNameCase);
|
||||
begin
|
||||
AppendFromJSONArrayString(AJSONArrayString, AIgnoredFields, AFieldNamePolicy);
|
||||
AppendFromJSONArrayString(AJSONArrayString, AIgnoredFields, FieldNameCase);
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadFromJSONArray(AJSONArray: TJSONArray; AFieldNamePolicy: TFieldNamePolicy);
|
||||
procedure TDataSetHelper.LoadFromJSONArray(AJSONArray: TJSONArray; FieldNameCase: TMVCNameCase);
|
||||
var
|
||||
lSerializer: TMVCJsonDataObjectsSerializer;
|
||||
lBookmark: TArray<Byte>;
|
||||
@ -336,7 +336,7 @@ begin
|
||||
try
|
||||
lSerializer := TMVCJsonDataObjectsSerializer.Create;
|
||||
try
|
||||
lSerializer.JsonArrayToDataSet(AJSONArray, Self, nil, ncAsIs);
|
||||
lSerializer.JsonArrayToDataSet(AJSONArray, Self, nil, FieldNameCase);
|
||||
finally
|
||||
lSerializer.Free;
|
||||
end;
|
||||
@ -347,15 +347,15 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadFromJSONArrayString(AJSONArrayString: string; AFieldNamePolicy: TFieldNamePolicy);
|
||||
procedure TDataSetHelper.LoadFromJSONArrayString(AJSONArrayString: string; FieldNameCase: TMVCNameCase);
|
||||
begin
|
||||
AppendFromJSONArrayString(AJSONArrayString, TArray<string>.Create(), AFieldNamePolicy);
|
||||
AppendFromJSONArrayString(AJSONArrayString, TArray<string>.Create(), FieldNameCase);
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.AppendFromJSONArrayString(AJSONArrayString: string; AIgnoredFields: TArray<string>;
|
||||
AFieldNamePolicy: TFieldNamePolicy);
|
||||
FieldNameCase: TMVCNameCase);
|
||||
begin
|
||||
LoadFromJSONArray(AJSONArrayString, AFieldNamePolicy);
|
||||
LoadFromJSONArray(AJSONArrayString, FieldNameCase);
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.AppendFromJSONArrayString(AJSONArrayString: string);
|
||||
@ -363,25 +363,26 @@ begin
|
||||
AppendFromJSONArrayString(AJSONArrayString, TArray<string>.Create());
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadFromJSONObject(AJSONObject: TJSONObject; AIgnoredFields: TArray<string>;
|
||||
AFieldNamePolicy: TFieldNamePolicy);
|
||||
procedure TDataSetHelper.LoadFromJSONObject(const JSONObject: TJSONObject; const AIgnoredFields: TArray<string>;
|
||||
const FieldNameCase: TMVCNameCase);
|
||||
begin
|
||||
raise Exception.Create('Not Implemented');
|
||||
// Mapper.JSONObjectToDataSet(AJSONObject, Self, AIgnoredFields, false,
|
||||
// AFieldNamePolicy);
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadFromJSONObjectString(AJSONObjectString: string; AIgnoredFields: TArray<string>);
|
||||
procedure TDataSetHelper.LoadFromJSONObjectString(const JSONObjectString: string; const IgnoredFields: TArray<string>;
|
||||
const FieldNameCase: TMVCNameCase);
|
||||
var
|
||||
lSerializer: IMVCSerializer;
|
||||
begin
|
||||
lSerializer := TMVCJsonDataObjectsSerializer.Create;
|
||||
lSerializer.DeserializeDataSetRecord(AJSONObjectString, Self, nil, ncAsIs);
|
||||
lSerializer.DeserializeDataSetRecord(JSONObjectString, Self, TMVCIgnoredList(IgnoredFields), FieldNameCase);
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadFromJSONObject(AJSONObject: TJSONObject; AFieldNamePolicy: TFieldNamePolicy);
|
||||
procedure TDataSetHelper.LoadFromJSONObject(const JSONObject: TJSONObject; const FieldNameCase: TMVCNameCase);
|
||||
begin
|
||||
LoadFromJSONObject(AJSONObject, TArray<string>.Create());
|
||||
LoadFromJSONObject(JSONObject, TArray<string>.Create(), FieldNameCase);
|
||||
end;
|
||||
|
||||
procedure TDataSetHelper.LoadFromJSONObjectString(AJSONObjectString: string);
|
||||
|
@ -324,11 +324,10 @@ function NewCollectionHolder(const AList: TObject; const AMetaFiller: TProc<TMVC
|
||||
function MakeResponseData(const AObject: TObject; const AMeta: TMVCStringDictionary = nil;
|
||||
const AOwns: boolean = True): IMVCResponseData;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
MVCFramework.Serializer.JsonDataObjects,
|
||||
MVCFramework.Serializer.Intf,
|
||||
Data.FmtBcd,
|
||||
MVCFramework.Nullables,
|
||||
System.Generics.Defaults;
|
||||
|
@ -49,7 +49,7 @@ type
|
||||
[TestFixture]
|
||||
TMVCTestSerializerJsonDataObjects = class(TObject)
|
||||
private
|
||||
FSerializer: IMVCSerializer;
|
||||
fSerializer: IMVCSerializer;
|
||||
public
|
||||
[Setup]
|
||||
procedure Setup;
|
||||
@ -85,6 +85,8 @@ type
|
||||
procedure TestSerializeCollection;
|
||||
[Test]
|
||||
procedure TestSerializeDataSet;
|
||||
[Test]
|
||||
procedure TestDataSetHelpers;
|
||||
{ deserialize declarations }
|
||||
[Test]
|
||||
procedure TestDeserializeEntity;
|
||||
@ -177,19 +179,132 @@ const
|
||||
procedure TMVCTestSerializerJsonDataObjects.Setup;
|
||||
begin
|
||||
inherited;
|
||||
FSerializer := TMVCJsonDataObjectsSerializer.Create;
|
||||
FSerializer.RegisterTypeSerializer(System.TypeInfo(TStream), TMVCStreamSerializerJsonDataObject.Create);
|
||||
FSerializer.RegisterTypeSerializer(System.TypeInfo(TStringStream), TMVCStreamSerializerJsonDataObject.Create);
|
||||
FSerializer.RegisterTypeSerializer(System.TypeInfo(TMemoryStream), TMVCStreamSerializerJsonDataObject.Create);
|
||||
FSerializer.RegisterTypeSerializer(System.TypeInfo(TEntityCustom), TMVCEntityCustomSerializerJsonDataObjects.Create);
|
||||
FSerializer.RegisterTypeSerializer(System.TypeInfo(TMVCNullable<Integer>),
|
||||
fSerializer := TMVCJsonDataObjectsSerializer.Create;
|
||||
fSerializer.RegisterTypeSerializer(System.TypeInfo(TStream), TMVCStreamSerializerJsonDataObject.Create);
|
||||
fSerializer.RegisterTypeSerializer(System.TypeInfo(TStringStream), TMVCStreamSerializerJsonDataObject.Create);
|
||||
fSerializer.RegisterTypeSerializer(System.TypeInfo(TMemoryStream), TMVCStreamSerializerJsonDataObject.Create);
|
||||
fSerializer.RegisterTypeSerializer(System.TypeInfo(TEntityCustom), TMVCEntityCustomSerializerJsonDataObjects.Create);
|
||||
fSerializer.RegisterTypeSerializer(System.TypeInfo(TMVCNullable<Integer>),
|
||||
TMVCNullableIntegerSerializerJsonDataObjects.Create);
|
||||
end;
|
||||
|
||||
procedure TMVCTestSerializerJsonDataObjects.TearDown;
|
||||
begin
|
||||
inherited;
|
||||
FSerializer := nil;
|
||||
fSerializer := nil;
|
||||
end;
|
||||
|
||||
procedure TMVCTestSerializerJsonDataObjects.TestDataSetHelpers;
|
||||
const
|
||||
JSON =
|
||||
'{' +
|
||||
'"Id":1,' +
|
||||
'"Code":2,' +
|
||||
'"Name":"Ezequiel Juliano Müller",' +
|
||||
'"Salary":100,' +
|
||||
'"Birthday":"1987-10-15",' +
|
||||
'"AccessDateTime":"2017-02-17T16:37:50.000Z",' +
|
||||
'"AccessTime":"16:40:50",' +
|
||||
'"Active":true,' +
|
||||
'"Amount":100,' +
|
||||
'"BlobFld":"PGh0bWw+PGJvZHk+PGgxPkJMT0I8L2gxPjwvYm9keT48L2h0bWw+",' +
|
||||
'"Items":[' +
|
||||
'{' +
|
||||
'"Id":1,' +
|
||||
'"Name":"Ezequiel Juliano Müller"' +
|
||||
'},' +
|
||||
'{' +
|
||||
'"Id":2,' +
|
||||
'"Name":"Juliano"' +
|
||||
'}' +
|
||||
'],' +
|
||||
'"Departament":{' +
|
||||
'"Name":"Depto1"' +
|
||||
'},' +
|
||||
'"GUID":"{9386C957-5379-4370-8492-8FA464A9CF0C}"' +
|
||||
'}';
|
||||
|
||||
JSON_LOWERCASE =
|
||||
'{' +
|
||||
'"id":1,' +
|
||||
'"name":"Ezequiel Juliano Müller"' +
|
||||
'}';
|
||||
|
||||
JSON_UPPERCASE =
|
||||
'{' +
|
||||
'"ID":1,' +
|
||||
'"NAME":"Ezequiel Juliano Müller"' +
|
||||
'}';
|
||||
|
||||
JSON_ASIS =
|
||||
'{' +
|
||||
'"Id":1,' +
|
||||
'"Name":"Ezequiel Juliano Müller"' +
|
||||
'}';
|
||||
|
||||
JSON_LIST =
|
||||
'[' +
|
||||
'{' +
|
||||
'"Id_Id":1,' +
|
||||
'"Name_Name":"Ezequiel Juliano Müller"' +
|
||||
'},' +
|
||||
'{' +
|
||||
'"Id_Id":2,' +
|
||||
'"Name_Name":"Ezequiel Juliano Müller"' +
|
||||
'}' +
|
||||
']';
|
||||
|
||||
var
|
||||
Dm: TEntitiesModule;
|
||||
S: string;
|
||||
begin
|
||||
Dm := TEntitiesModule.Create(nil);
|
||||
try
|
||||
Dm.Entity.Insert;
|
||||
Dm.EntityId.AsLargeInt := 1;
|
||||
Dm.EntityCode.AsInteger := 2;
|
||||
Dm.EntityName.AsString := 'Ezequiel Juliano Müller';
|
||||
Dm.EntityBirthday.AsDateTime := StrToDate('15/10/1987');
|
||||
Dm.EntityAccessDateTime.AsDateTime := StrToDateTime('17/02/2017 16:37:50');
|
||||
Dm.EntityAccessTime.AsDateTime := StrToTime('16:40:50');
|
||||
Dm.EntityActive.AsBoolean := True;
|
||||
Dm.EntitySalary.AsCurrency := 100;
|
||||
Dm.EntityAmount.AsFloat := 100;
|
||||
Dm.EntityBlobFld.AsString := '<html><body><h1>BLOB</h1></body></html>';
|
||||
Dm.EntityGUID.AsGuid := StringToGUID('{9386C957-5379-4370-8492-8FA464A9CF0C}');
|
||||
|
||||
Dm.Item.Insert;
|
||||
Dm.ItemId.AsLargeInt := 1;
|
||||
Dm.ItemName.AsString := 'Ezequiel Juliano Müller';
|
||||
Dm.Item.Post;
|
||||
|
||||
Dm.Item.Insert;
|
||||
Dm.ItemId.AsLargeInt := 2;
|
||||
Dm.ItemName.AsString := 'Juliano';
|
||||
Dm.Item.Post;
|
||||
|
||||
Dm.Departament.Insert;
|
||||
Dm.DepartamentName.AsString := 'Depto1';
|
||||
Dm.Departament.Post;
|
||||
|
||||
S := Dm.Entity.AsJSONObject(ncAsIs, ['Ignored']);
|
||||
Assert.areEqual(JSON, S, False);
|
||||
|
||||
Dm.Item.First;
|
||||
S := Dm.Item.AsJSONObject(ncAsIs);
|
||||
Assert.areEqual(JSON_ASIS, S, False);
|
||||
|
||||
Dm.Item.First;
|
||||
S := Dm.Item.AsJSONObject(ncUpperCase);
|
||||
Assert.areEqual(JSON_UPPERCASE, S, False);
|
||||
|
||||
Dm.Item.First;
|
||||
S := Dm.Item.AsJSONObject(ncLowerCase);
|
||||
Assert.areEqual(JSON_LOWERCASE, S, False);
|
||||
|
||||
finally
|
||||
Dm.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMVCTestSerializerJsonDataObjects.TestDeserializeCollection;
|
||||
@ -240,7 +355,7 @@ var
|
||||
begin
|
||||
O := TObjectList<TNote>.Create(True);
|
||||
try
|
||||
FSerializer.DeserializeCollection(JSON_PROPERTIES, O, TNote);
|
||||
fSerializer.DeserializeCollection(JSON_PROPERTIES, O, TNote);
|
||||
CheckObjectList(O);
|
||||
finally
|
||||
O.Free;
|
||||
@ -248,7 +363,7 @@ begin
|
||||
|
||||
O := TObjectList<TNote>.Create(True);
|
||||
try
|
||||
FSerializer.DeserializeCollection(JSON_FIELDS, O, TNote, stFields);
|
||||
fSerializer.DeserializeCollection(JSON_FIELDS, O, TNote, stFields);
|
||||
CheckObjectList(O);
|
||||
finally
|
||||
O.Free;
|
||||
@ -333,7 +448,7 @@ var
|
||||
begin
|
||||
Dm := TEntitiesModule.Create(nil);
|
||||
try
|
||||
FSerializer.DeserializeDataSetRecord(JSON, Dm.Entity, ['Ignored']);
|
||||
fSerializer.DeserializeDataSetRecord(JSON, Dm.Entity, ['Ignored']);
|
||||
Assert.isTrue(Dm.EntityId.AsLargeInt = 1);
|
||||
Assert.isTrue(Dm.EntityCode.AsInteger = 2);
|
||||
Assert.isTrue(Dm.EntityName.AsString = 'Ezequiel Juliano Müller');
|
||||
@ -357,24 +472,24 @@ begin
|
||||
Dm.Departament.First;
|
||||
Assert.isTrue(Dm.DepartamentName.AsString = 'Depto1');
|
||||
|
||||
FSerializer.DeserializeDataSetRecord(JSON_LOWERCASE, Dm.EntityLowerCase);
|
||||
fSerializer.DeserializeDataSetRecord(JSON_LOWERCASE, Dm.EntityLowerCase);
|
||||
Assert.isTrue(Dm.EntityLowerCaseId.AsLargeInt = 1);
|
||||
Assert.isTrue(Dm.EntityLowerCaseName.AsString = 'Ezequiel Juliano Müller');
|
||||
|
||||
FSerializer.DeserializeDataSetRecord(JSON_UPPERCASE, Dm.EntityUpperCase);
|
||||
fSerializer.DeserializeDataSetRecord(JSON_UPPERCASE, Dm.EntityUpperCase);
|
||||
Assert.isTrue(Dm.EntityUpperCaseId.AsLargeInt = 1);
|
||||
Assert.isTrue(Dm.EntityUpperCaseName.AsString = 'Ezequiel Juliano Müller');
|
||||
|
||||
FSerializer.DeserializeDataSetRecord(JSON_UPPERCASE, Dm.EntityUpperCase2, [], ncUpperCase);
|
||||
fSerializer.DeserializeDataSetRecord(JSON_UPPERCASE, Dm.EntityUpperCase2, [], ncUpperCase);
|
||||
Assert.isTrue(Dm.EntityUpperCase2Id.AsLargeInt = 1);
|
||||
Assert.isTrue(Dm.EntityUpperCase2Name.AsString = 'Ezequiel Juliano Müller');
|
||||
|
||||
FSerializer.DeserializeDataSetRecord(JSON_ASIS, Dm.EntityAsIs);
|
||||
fSerializer.DeserializeDataSetRecord(JSON_ASIS, Dm.EntityAsIs);
|
||||
Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 1);
|
||||
Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller');
|
||||
|
||||
Dm.EntityAsIs.EmptyDataSet;
|
||||
FSerializer.DeserializeDataSet(JSON_LIST, Dm.EntityAsIs);
|
||||
fSerializer.DeserializeDataSet(JSON_LIST, Dm.EntityAsIs);
|
||||
Dm.EntityAsIs.First;
|
||||
Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 1);
|
||||
Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller');
|
||||
@ -384,7 +499,7 @@ begin
|
||||
Assert.isTrue(Dm.EntityAsIsName.AsString = 'Ezequiel Juliano Müller');
|
||||
|
||||
Dm.EntityAsIs.EmptyDataSet;
|
||||
Dm.EntityAsIs.LoadJSONArrayFromJSONObjectProperty(JSON_ITEMS, 'items');
|
||||
Dm.EntityAsIs.LoadJSONArrayFromJSONObjectProperty(JSON_ITEMS, 'items', ncAsIs);
|
||||
Dm.EntityAsIs.First;
|
||||
Assert.isTrue(Dm.EntityAsIsId.AsLargeInt = 1);
|
||||
Assert.isTrue(Dm.EntityAsIsName.AsString = 'Pedro Henrique de Oliveira');
|
||||
@ -510,7 +625,7 @@ var
|
||||
begin
|
||||
O := TEntity.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(JSON_PROPERTIES, O);
|
||||
fSerializer.DeserializeObject(JSON_PROPERTIES, O);
|
||||
CheckObject(O);
|
||||
finally
|
||||
O.Free;
|
||||
@ -518,7 +633,7 @@ begin
|
||||
|
||||
O := TEntity.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(JSON_FIELDS, O, stFields);
|
||||
fSerializer.DeserializeObject(JSON_FIELDS, O, stFields);
|
||||
CheckObject(O);
|
||||
finally
|
||||
O.Free;
|
||||
@ -542,7 +657,7 @@ var
|
||||
begin
|
||||
O := TSale.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(JSON, O);
|
||||
fSerializer.DeserializeObject(JSON, O);
|
||||
Assert.isTrue(O.Entity.Id = 1);
|
||||
Assert.isTrue(O.Entity.Code = 2);
|
||||
Assert.isTrue(O.Entity.Name = 'Ezequiel Juliano Müller');
|
||||
@ -566,7 +681,7 @@ var
|
||||
begin
|
||||
O := TEntityCustom.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(JSON, O);
|
||||
fSerializer.DeserializeObject(JSON, O);
|
||||
Assert.isTrue(O.Id = 1);
|
||||
Assert.isTrue(O.Code = 2);
|
||||
Assert.isTrue(O.Name = 'Ezequiel Juliano Müller');
|
||||
@ -589,7 +704,7 @@ var
|
||||
begin
|
||||
O := TEntityCustomWithNullables.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(JSON, O);
|
||||
fSerializer.DeserializeObject(JSON, O);
|
||||
Assert.isTrue(O.Id = 1);
|
||||
Assert.isTrue(O.Code = 2);
|
||||
Assert.isTrue(O.Name = 'Ezequiel Juliano Müller');
|
||||
@ -619,7 +734,7 @@ var
|
||||
begin
|
||||
OFields := TEntitySerializeFields.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(JSON_FIELDS, OFields);
|
||||
fSerializer.DeserializeObject(JSON_FIELDS, OFields);
|
||||
Assert.isTrue(OFields.Id = 1);
|
||||
Assert.isTrue(OFields.Code = 2);
|
||||
Assert.isTrue(OFields.Name = 'Ezequiel Juliano Müller');
|
||||
@ -629,7 +744,7 @@ begin
|
||||
|
||||
OProperties := TEntitySerializeProperties.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(JSON_PROPERTIES, OProperties);
|
||||
fSerializer.DeserializeObject(JSON_PROPERTIES, OProperties);
|
||||
Assert.isTrue(OProperties.Id = 1);
|
||||
Assert.isTrue(OProperties.Code = 2);
|
||||
Assert.isTrue(OProperties.Name = 'Ezequiel Juliano Müller');
|
||||
@ -660,7 +775,7 @@ var
|
||||
begin
|
||||
O := TEntityWithArray.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(JSON_WITH_ARRAY, O);
|
||||
fSerializer.DeserializeObject(JSON_WITH_ARRAY, O);
|
||||
CheckObject(O);
|
||||
finally
|
||||
O.Free;
|
||||
@ -675,11 +790,11 @@ begin
|
||||
lObj1 := BusinessObjectsU.TNullablesTest.Create;
|
||||
try
|
||||
lObj1.LoadSomeData;
|
||||
lSer := FSerializer.SerializeObject(lObj1);
|
||||
lSer := fSerializer.SerializeObject(lObj1);
|
||||
lObj2 := BusinessObjectsU.TNullablesTest.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(lSer, lObj2);
|
||||
Assert.IsTrue(lObj1.Equals(lObj2));
|
||||
fSerializer.DeserializeObject(lSer, lObj2);
|
||||
Assert.isTrue(lObj1.Equals(lObj2));
|
||||
finally
|
||||
lObj2.Free;
|
||||
end;
|
||||
@ -695,11 +810,11 @@ var
|
||||
begin
|
||||
lObj1 := GetMyObject;
|
||||
try
|
||||
lSer := FSerializer.SerializeObject(lObj1);
|
||||
lSer := fSerializer.SerializeObject(lObj1);
|
||||
lObj2 := TMyObject.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(lSer, lObj2);
|
||||
Assert.IsTrue(lObj1.Equals(lObj2));
|
||||
fSerializer.DeserializeObject(lSer, lObj2);
|
||||
Assert.isTrue(lObj1.Equals(lObj2));
|
||||
finally
|
||||
lObj2.Free;
|
||||
end;
|
||||
@ -719,19 +834,19 @@ begin
|
||||
try
|
||||
for I := 0 to 9 do
|
||||
begin
|
||||
lObj :=GetMyObject;
|
||||
lObj := GetMyObject;
|
||||
lObj.PropJSONObject.I['value'] := I;
|
||||
lList1.Add(lObj);
|
||||
end;
|
||||
|
||||
lSer := FSerializer.SerializeCollection(lList1);
|
||||
lSer := fSerializer.SerializeCollection(lList1);
|
||||
|
||||
lList2 := TObjectList<TMyObject>.Create;
|
||||
try
|
||||
FSerializer.DeserializeCollection(lSer, lList2, TMyObject);
|
||||
fSerializer.DeserializeCollection(lSer, lList2, TMyObject);
|
||||
for I := 0 to 9 do
|
||||
begin
|
||||
Assert.IsTrue(lList1[I].Equals(lList2[I]));
|
||||
Assert.isTrue(lList1[I].Equals(lList2[I]));
|
||||
end;
|
||||
finally
|
||||
lList2.Free;
|
||||
@ -785,10 +900,10 @@ begin
|
||||
O.Add(TNote.Create('Description 3'));
|
||||
O.Add(TNote.Create('Description 4'));
|
||||
|
||||
S := FSerializer.SerializeCollection(O);
|
||||
S := fSerializer.SerializeCollection(O);
|
||||
Assert.areEqual(JSON, S);
|
||||
|
||||
S := FSerializer.SerializeCollection(O, stFields);
|
||||
S := fSerializer.SerializeCollection(O, stFields);
|
||||
Assert.areEqual(JSON_FIELDS, S);
|
||||
finally
|
||||
O.Free;
|
||||
@ -889,36 +1004,36 @@ begin
|
||||
Dm.Departament.Post;
|
||||
|
||||
Dm.Entity.Post;
|
||||
S := FSerializer.SerializeDataSetRecord(Dm.Entity, ['Ignored'], ncAsIs);
|
||||
Assert.areEqual(JSON, S);
|
||||
S := fSerializer.SerializeDataSetRecord(Dm.Entity, ['Ignored'], ncAsIs);
|
||||
Assert.areEqual(JSON, S, False);
|
||||
|
||||
Dm.EntityLowerCase.Insert;
|
||||
Dm.EntityLowerCaseId.AsLargeInt := 1;
|
||||
Dm.EntityLowerCaseName.AsString := 'Ezequiel Juliano Müller';
|
||||
Dm.EntityLowerCase.Post;
|
||||
S := FSerializer.SerializeDataSetRecord(Dm.EntityLowerCase);
|
||||
Assert.areEqual(JSON_LOWERCASE, S, 'json lowercase');
|
||||
S := fSerializer.SerializeDataSetRecord(Dm.EntityLowerCase);
|
||||
Assert.areEqual(JSON_LOWERCASE, S, False, 'json lowercase');
|
||||
|
||||
Dm.EntityUpperCase.Insert;
|
||||
Dm.EntityUpperCaseId.AsLargeInt := 1;
|
||||
Dm.EntityUpperCaseName.AsString := 'Ezequiel Juliano Müller';
|
||||
Dm.EntityUpperCase.Post;
|
||||
S := FSerializer.SerializeDataSetRecord(Dm.EntityUpperCase);
|
||||
Assert.areEqual(JSON_UPPERCASE, S, 'json uppercase (1)');
|
||||
S := fSerializer.SerializeDataSetRecord(Dm.EntityUpperCase);
|
||||
Assert.areEqual(JSON_UPPERCASE, S, False, 'json uppercase (1)');
|
||||
|
||||
Dm.EntityUpperCase2.Insert;
|
||||
Dm.EntityUpperCase2Id.AsLargeInt := 1;
|
||||
Dm.EntityUpperCase2Name.AsString := 'Ezequiel Juliano Müller';
|
||||
Dm.EntityUpperCase2.Post;
|
||||
S := FSerializer.SerializeDataSetRecord(Dm.EntityUpperCase2, [], ncUpperCase);
|
||||
Assert.areEqual(JSON_UPPERCASE, S, 'json uppercase (2)');
|
||||
S := fSerializer.SerializeDataSetRecord(Dm.EntityUpperCase2, [], ncUpperCase);
|
||||
Assert.areEqual(JSON_UPPERCASE, S, False, 'json uppercase (2)');
|
||||
|
||||
Dm.EntityAsIs.Insert;
|
||||
Dm.EntityAsIsId.AsLargeInt := 1;
|
||||
Dm.EntityAsIsName.AsString := 'Ezequiel Juliano Müller';
|
||||
Dm.EntityAsIs.Post;
|
||||
S := FSerializer.SerializeDataSetRecord(Dm.EntityAsIs);
|
||||
Assert.areEqual(JSON_ASIS, S, 'json as is');
|
||||
S := fSerializer.SerializeDataSetRecord(Dm.EntityAsIs);
|
||||
Assert.areEqual(JSON_ASIS, S, False, 'json as is');
|
||||
|
||||
Dm.EntityAsIs.Append;
|
||||
Dm.EntityAsIsId.AsLargeInt := 2;
|
||||
@ -926,12 +1041,12 @@ begin
|
||||
Dm.EntityAsIs.Post;
|
||||
|
||||
// serialize dataset
|
||||
S := FSerializer.SerializeDataSet(Dm.EntityAsIs);
|
||||
Assert.areEqual(JSON_LIST, S, 'json list');
|
||||
S := fSerializer.SerializeDataSet(Dm.EntityAsIs);
|
||||
Assert.areEqual(JSON_LIST, S, False, 'json list');
|
||||
|
||||
// serialize dataset as object
|
||||
S := FSerializer.SerializeObject(Dm.EntityAsIs);
|
||||
Assert.areEqual(JSON_LIST, S, 'json list');
|
||||
S := fSerializer.SerializeObject(Dm.EntityAsIs);
|
||||
Assert.areEqual(JSON_LIST, S, False, 'json list');
|
||||
|
||||
finally
|
||||
Dm.Free;
|
||||
@ -963,7 +1078,7 @@ begin
|
||||
O.MonthName := TMonthEnum.meJanuary;
|
||||
O.MonthName2 := TMonthEnum.meFebruary;
|
||||
O.MonthOrder := TMonthEnum.meJanuary;
|
||||
S := FSerializer.SerializeObject(O);
|
||||
S := fSerializer.SerializeObject(O);
|
||||
Assert.areEqual(JSON, S);
|
||||
finally
|
||||
O.Free;
|
||||
@ -971,7 +1086,7 @@ begin
|
||||
|
||||
O := TEntityWithEnums.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(S, O);
|
||||
fSerializer.DeserializeObject(S, O);
|
||||
Assert.areEqual(int64(1), O.Id);
|
||||
Assert.areEqual(2, O.Code);
|
||||
Assert.areEqual('Daniele Teti', O.Name);
|
||||
@ -992,7 +1107,7 @@ begin
|
||||
Dm := TEntitiesModule.Create(nil);
|
||||
try
|
||||
Dm.Entity.EmptyDataSet;
|
||||
S := FSerializer.SerializeDataSet(Dm.Entity);
|
||||
S := fSerializer.SerializeDataSet(Dm.Entity);
|
||||
Assert.areEqual('[]', S);
|
||||
finally
|
||||
Dm.Free;
|
||||
@ -1150,16 +1265,16 @@ begin
|
||||
O.Department.Notes.Add(TNote.Create('DepNote1'));
|
||||
O.Department.Notes.Add(TNote.Create('DepNote2'));
|
||||
|
||||
S := FSerializer.SerializeObject(O, stProperties, ['Ignored']);
|
||||
S := fSerializer.SerializeObject(O, stProperties, ['Ignored']);
|
||||
Assert.areEqual(JSON_PROPERTIES, S);
|
||||
|
||||
S := FSerializer.SerializeObject(O, stFields, ['FIgnored']);
|
||||
S := fSerializer.SerializeObject(O, stFields, ['FIgnored']);
|
||||
Assert.areEqual(JSON_FIELDS, S);
|
||||
|
||||
O.Birthday := 0;
|
||||
O.AccessDateTime := 0;
|
||||
O.AccessTime := 0;
|
||||
S := FSerializer.SerializeObject(O, stProperties, ['Ignored']);
|
||||
S := fSerializer.SerializeObject(O, stProperties, ['Ignored']);
|
||||
Assert.areEqual(JSON_NULLS, S);
|
||||
finally
|
||||
O.Free;
|
||||
@ -1190,7 +1305,7 @@ begin
|
||||
O.Notes.WriteString('Ezequiel Juliano Müller');
|
||||
O.NotesAsString.WriteString('Ezequiel Juliano Müller');
|
||||
|
||||
S := FSerializer.SerializeObject(O);
|
||||
S := fSerializer.SerializeObject(O);
|
||||
Assert.areEqual(JSON, S);
|
||||
finally
|
||||
O.Free;
|
||||
@ -1215,7 +1330,7 @@ begin
|
||||
O.Code := 2;
|
||||
O.Name := 'Ezequiel Juliano Müller';
|
||||
|
||||
S := FSerializer.SerializeObject(O);
|
||||
S := fSerializer.SerializeObject(O);
|
||||
Assert.areEqual(JSON, S);
|
||||
finally
|
||||
O.Free;
|
||||
@ -1240,7 +1355,7 @@ begin
|
||||
O.Code := 2;
|
||||
O.Name := 'Ezequiel Juliano Müller';
|
||||
|
||||
S := FSerializer.SerializeObject(O);
|
||||
S := fSerializer.SerializeObject(O);
|
||||
Assert.areEqual(JSON, S);
|
||||
finally
|
||||
O.Free;
|
||||
@ -1265,10 +1380,10 @@ begin
|
||||
O.Code := 2;
|
||||
O.Name := 'Ezequiel Juliano Müller';
|
||||
|
||||
S := FSerializer.SerializeObject(O);
|
||||
S := fSerializer.SerializeObject(O);
|
||||
Assert.areEqual(JSON, S);
|
||||
|
||||
S := FSerializer.SerializeObject(O, stFields);
|
||||
S := fSerializer.SerializeObject(O, stFields);
|
||||
Assert.areEqual(JSON, S);
|
||||
finally
|
||||
O.Free;
|
||||
@ -1301,7 +1416,7 @@ begin
|
||||
OFields.Code := 2;
|
||||
OFields.Name := 'Ezequiel Juliano Müller';
|
||||
|
||||
S := FSerializer.SerializeObject(OFields);
|
||||
S := fSerializer.SerializeObject(OFields);
|
||||
Assert.areEqual(JSON_FIELDS, S);
|
||||
finally
|
||||
OFields.Free;
|
||||
@ -1313,7 +1428,7 @@ begin
|
||||
OProperties.Code := 2;
|
||||
OProperties.Name := 'Ezequiel Juliano Müller';
|
||||
|
||||
S := FSerializer.SerializeObject(OProperties);
|
||||
S := fSerializer.SerializeObject(OProperties);
|
||||
Assert.areEqual(JSON_PROPERTIES, S);
|
||||
finally
|
||||
OProperties.Free;
|
||||
@ -1338,7 +1453,7 @@ begin
|
||||
O.Code := 2;
|
||||
O.Name := 'Ezequiel Juliano Müller';
|
||||
|
||||
S := FSerializer.SerializeObject(O);
|
||||
S := fSerializer.SerializeObject(O);
|
||||
Assert.areEqual(JSON, S);
|
||||
finally
|
||||
O.Free;
|
||||
@ -1363,7 +1478,7 @@ begin
|
||||
O.Names := ['Pedro', 'Oliveira'];
|
||||
O.Values := [1, 2];
|
||||
|
||||
S := FSerializer.SerializeObject(O);
|
||||
S := fSerializer.SerializeObject(O);
|
||||
Assert.areEqual(JSON_WITH_ARRAY, S);
|
||||
finally
|
||||
O.Free;
|
||||
@ -1376,9 +1491,9 @@ const
|
||||
'{' +
|
||||
'"Id":1,' +
|
||||
'"Name":"João Antônio Duarte",' +
|
||||
'"ChildEntity":{'+
|
||||
'"Code":10,'+
|
||||
'"Description":"Child Entity"'+
|
||||
'"ChildEntity":{' +
|
||||
'"Code":10,' +
|
||||
'"Description":"Child Entity"' +
|
||||
'}' +
|
||||
'}';
|
||||
var
|
||||
@ -1391,15 +1506,15 @@ begin
|
||||
LEntity.ChildEntity.Code := 10;
|
||||
LEntity.ChildEntity.Description := 'Child Entity';
|
||||
|
||||
LJson := FSerializer.SerializeObject(LEntity);
|
||||
Assert.AreEqual(JSON, LJson);
|
||||
LJson := fSerializer.SerializeObject(LEntity);
|
||||
Assert.areEqual(JSON, LJson);
|
||||
|
||||
LEntity := TEntityWithInterface.Create;
|
||||
FSerializer.DeserializeObject(LJson, LEntity);
|
||||
Assert.AreEqual(Integer(1), LEntity.Id);
|
||||
Assert.AreEqual('João Antônio Duarte', LEntity.Name);
|
||||
Assert.AreEqual(Integer(10), LEntity.ChildEntity.Code);
|
||||
Assert.AreEqual('Child Entity', LEntity.ChildEntity.Description);
|
||||
fSerializer.DeserializeObject(LJson, LEntity);
|
||||
Assert.areEqual(Integer(1), LEntity.Id);
|
||||
Assert.areEqual('João Antônio Duarte', LEntity.Name);
|
||||
Assert.areEqual(Integer(10), LEntity.ChildEntity.Code);
|
||||
Assert.areEqual('Child Entity', LEntity.ChildEntity.Description);
|
||||
end;
|
||||
|
||||
procedure TMVCTestSerializerJsonDataObjects.TestSerializeDeserializeGenericEntity;
|
||||
@ -1414,7 +1529,7 @@ const
|
||||
'{"Description":"Description 03"},' +
|
||||
'{"Description":"Description 04"},' +
|
||||
'{"Description":"Description 05"}' +
|
||||
']'+
|
||||
']' +
|
||||
'}';
|
||||
var
|
||||
LGenericEntity: TGenericEntity<TNote>;
|
||||
@ -1431,25 +1546,25 @@ begin
|
||||
LGenericEntity.Items.Add(TNote.Create('Description 04'));
|
||||
LGenericEntity.Items.Add(TNote.Create('Description 05'));
|
||||
|
||||
LJson := FSerializer.SerializeObject(LGenericEntity);
|
||||
LJson := fSerializer.SerializeObject(LGenericEntity);
|
||||
|
||||
Assert.AreEqual(JSON, LJson);
|
||||
Assert.areEqual(JSON, LJson);
|
||||
finally
|
||||
LGenericEntity.Free;
|
||||
end;
|
||||
|
||||
LGenericEntity := TGenericEntity<TNote>.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(LJson, LGenericEntity);
|
||||
fSerializer.DeserializeObject(LJson, LGenericEntity);
|
||||
|
||||
Assert.AreEqual(Integer(1), LGenericEntity.Code);
|
||||
Assert.AreEqual('General Description', LGenericEntity.Description);
|
||||
Assert.AreEqual(Integer(5), LGenericEntity.Items.Count);
|
||||
Assert.AreEqual('Description 01', LGenericEntity.Items[0].Description);
|
||||
Assert.AreEqual('Description 02', LGenericEntity.Items[1].Description);
|
||||
Assert.AreEqual('Description 03', LGenericEntity.Items[2].Description);
|
||||
Assert.AreEqual('Description 04', LGenericEntity.Items[3].Description);
|
||||
Assert.AreEqual('Description 05', LGenericEntity.Items[4].Description);
|
||||
Assert.areEqual(Integer(1), LGenericEntity.Code);
|
||||
Assert.areEqual('General Description', LGenericEntity.Description);
|
||||
Assert.areEqual(Integer(5), LGenericEntity.Items.Count);
|
||||
Assert.areEqual('Description 01', LGenericEntity.Items[0].Description);
|
||||
Assert.areEqual('Description 02', LGenericEntity.Items[1].Description);
|
||||
Assert.areEqual('Description 03', LGenericEntity.Items[2].Description);
|
||||
Assert.areEqual('Description 04', LGenericEntity.Items[3].Description);
|
||||
Assert.areEqual('Description 05', LGenericEntity.Items[4].Description);
|
||||
|
||||
finally
|
||||
LGenericEntity.Free;
|
||||
@ -1474,22 +1589,22 @@ begin
|
||||
try
|
||||
LEntity.Id := 1;
|
||||
LEntity.Code := 2;
|
||||
LEntity.name := 'João Antônio';
|
||||
LEntity.GuidValue := StringToGuid('{AEED1A0F-9061-40F0-9FDA-D69AE7F20222}');
|
||||
LEntity.Name := 'João Antônio';
|
||||
LEntity.GuidValue := StringToGUID('{AEED1A0F-9061-40F0-9FDA-D69AE7F20222}');
|
||||
|
||||
LJson := FSerializer.SerializeObject(LEntity);
|
||||
Assert.AreEqual(JSON, LJson);
|
||||
LJson := fSerializer.SerializeObject(LEntity);
|
||||
Assert.areEqual(JSON, LJson);
|
||||
finally
|
||||
LEntity.Free;
|
||||
end;
|
||||
|
||||
LEntity := TEntityCustomWithGuid.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(LJson, LEntity);
|
||||
Assert.AreEqual(Int64(1), LEntity.Id);
|
||||
Assert.AreEqual(Integer(2), LEntity.Code);
|
||||
Assert.AreEqual('João Antônio', LEntity.name);
|
||||
Assert.AreEqual(StringToGuid('{AEED1A0F-9061-40F0-9FDA-D69AE7F20222}'), LEntity.GuidValue);
|
||||
fSerializer.DeserializeObject(LJson, LEntity);
|
||||
Assert.areEqual(int64(1), LEntity.Id);
|
||||
Assert.areEqual(Integer(2), LEntity.Code);
|
||||
Assert.areEqual('João Antônio', LEntity.Name);
|
||||
Assert.areEqual(StringToGUID('{AEED1A0F-9061-40F0-9FDA-D69AE7F20222}'), LEntity.GuidValue);
|
||||
finally
|
||||
LEntity.Free;
|
||||
end;
|
||||
@ -1507,14 +1622,14 @@ const
|
||||
'{"Description":"Description 03"},' +
|
||||
'{"Description":"Description 04"},' +
|
||||
'{"Description":"Description 05"}' +
|
||||
'],'+
|
||||
'],' +
|
||||
'"Items2":[' +
|
||||
'{"Description":"Description2 01"},' +
|
||||
'{"Description":"Description2 02"},' +
|
||||
'{"Description":"Description2 03"},' +
|
||||
'{"Description":"Description2 04"},' +
|
||||
'{"Description":"Description2 05"}' +
|
||||
']'+
|
||||
']' +
|
||||
'}';
|
||||
var
|
||||
LGenericEntity: TMultipleGenericEntity<TNote, TNote>;
|
||||
@ -1537,34 +1652,33 @@ begin
|
||||
LGenericEntity.Items2.Add(TNote.Create('Description2 04'));
|
||||
LGenericEntity.Items2.Add(TNote.Create('Description2 05'));
|
||||
|
||||
LJson := fSerializer.SerializeObject(LGenericEntity);
|
||||
|
||||
LJson := FSerializer.SerializeObject(LGenericEntity);
|
||||
|
||||
Assert.AreEqual(JSON, LJson);
|
||||
Assert.areEqual(JSON, LJson);
|
||||
finally
|
||||
LGenericEntity.Free;
|
||||
end;
|
||||
|
||||
LGenericEntity := TMultipleGenericEntity<TNote, TNote>.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(LJson, LGenericEntity);
|
||||
fSerializer.DeserializeObject(LJson, LGenericEntity);
|
||||
|
||||
Assert.AreEqual(Integer(1), LGenericEntity.Code);
|
||||
Assert.AreEqual('General Description', LGenericEntity.Description);
|
||||
Assert.areEqual(Integer(1), LGenericEntity.Code);
|
||||
Assert.areEqual('General Description', LGenericEntity.Description);
|
||||
|
||||
Assert.AreEqual(Integer(5), LGenericEntity.Items.Count);
|
||||
Assert.AreEqual('Description 01', LGenericEntity.Items[0].Description);
|
||||
Assert.AreEqual('Description 02', LGenericEntity.Items[1].Description);
|
||||
Assert.AreEqual('Description 03', LGenericEntity.Items[2].Description);
|
||||
Assert.AreEqual('Description 04', LGenericEntity.Items[3].Description);
|
||||
Assert.AreEqual('Description 05', LGenericEntity.Items[4].Description);
|
||||
Assert.areEqual(Integer(5), LGenericEntity.Items.Count);
|
||||
Assert.areEqual('Description 01', LGenericEntity.Items[0].Description);
|
||||
Assert.areEqual('Description 02', LGenericEntity.Items[1].Description);
|
||||
Assert.areEqual('Description 03', LGenericEntity.Items[2].Description);
|
||||
Assert.areEqual('Description 04', LGenericEntity.Items[3].Description);
|
||||
Assert.areEqual('Description 05', LGenericEntity.Items[4].Description);
|
||||
|
||||
Assert.AreEqual(Integer(5), LGenericEntity.Items2.Count);
|
||||
Assert.AreEqual('Description2 01', LGenericEntity.Items2[0].Description);
|
||||
Assert.AreEqual('Description2 02', LGenericEntity.Items2[1].Description);
|
||||
Assert.AreEqual('Description2 03', LGenericEntity.Items2[2].Description);
|
||||
Assert.AreEqual('Description2 04', LGenericEntity.Items2[3].Description);
|
||||
Assert.AreEqual('Description2 05', LGenericEntity.Items2[4].Description);
|
||||
Assert.areEqual(Integer(5), LGenericEntity.Items2.Count);
|
||||
Assert.areEqual('Description2 01', LGenericEntity.Items2[0].Description);
|
||||
Assert.areEqual('Description2 02', LGenericEntity.Items2[1].Description);
|
||||
Assert.areEqual('Description2 03', LGenericEntity.Items2[2].Description);
|
||||
Assert.areEqual('Description2 04', LGenericEntity.Items2[3].Description);
|
||||
Assert.areEqual('Description2 05', LGenericEntity.Items2[4].Description);
|
||||
|
||||
finally
|
||||
LGenericEntity.Free;
|
||||
@ -1574,7 +1688,7 @@ end;
|
||||
|
||||
procedure TMVCTestSerializerJsonDataObjects.TestSerializeNil;
|
||||
begin
|
||||
Assert.areEqual('null', FSerializer.SerializeObject(nil));
|
||||
Assert.areEqual('null', fSerializer.SerializeObject(nil));
|
||||
end;
|
||||
|
||||
procedure TMVCTestSerializerJsonDataObjects.TestStringDictionary;
|
||||
@ -1588,10 +1702,10 @@ begin
|
||||
lDict['prop1'] := 'value1';
|
||||
lDict['prop2'] := 'value2';
|
||||
lDict['prop3'] := 'value3';
|
||||
lSerString := FSerializer.SerializeObject(lDict);
|
||||
lSerString := fSerializer.SerializeObject(lDict);
|
||||
lDict2 := TMVCStringDictionary.Create;
|
||||
try
|
||||
FSerializer.DeserializeObject(lSerString, lDict2);
|
||||
fSerializer.DeserializeObject(lSerString, lDict2);
|
||||
Assert.isTrue(lDict2.ContainsKey('prop1'));
|
||||
Assert.isTrue(lDict2.ContainsKey('prop2'));
|
||||
Assert.isTrue(lDict2.ContainsKey('prop3'));
|
||||
@ -1640,13 +1754,13 @@ procedure TMVCEntityCustomSerializerJsonDataObjects.DeserializeRoot(
|
||||
const ASerializerObject, AObject: TObject;
|
||||
const AAttributes: System.TArray<System.TCustomAttribute>);
|
||||
var
|
||||
lEntity: TEntityCustom;
|
||||
lJSON: TJDOJsonObject;
|
||||
LEntity: TEntityCustom;
|
||||
LJson: TJDOJsonObject;
|
||||
lAttr: TCustomAttribute;
|
||||
lAsLowerCase: Boolean;
|
||||
begin
|
||||
lEntity := TEntityCustom(AObject);
|
||||
lJSON := ASerializerObject as TJDOJsonObject;
|
||||
LEntity := TEntityCustom(AObject);
|
||||
LJson := ASerializerObject as TJDOJsonObject;
|
||||
lAsLowerCase := False;
|
||||
for lAttr in AAttributes do
|
||||
begin
|
||||
@ -1659,16 +1773,16 @@ begin
|
||||
|
||||
if lAsLowerCase then
|
||||
begin
|
||||
lEntity.Id := lJSON.I['id'];
|
||||
lEntity.Code := lJSON.I['code'];
|
||||
lEntity.Name := lJSON.S['name'];
|
||||
LEntity.Id := LJson.I['id'];
|
||||
LEntity.Code := LJson.I['code'];
|
||||
LEntity.Name := LJson.S['name'];
|
||||
end
|
||||
else
|
||||
begin
|
||||
// as is (upper case is not supported by the custom type serializer)
|
||||
lEntity.Id := lJSON.I['Id'];
|
||||
lEntity.Code := lJSON.I['Code'];
|
||||
lEntity.Name := lJSON.S['Name'];
|
||||
LEntity.Id := LJson.I['Id'];
|
||||
LEntity.Code := LJson.I['Code'];
|
||||
LEntity.Name := LJson.S['Name'];
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user