Added MVCNameCaseDefault global config variable (with updated tests and wizard)

This commit is contained in:
Daniele Teti 2024-06-08 23:05:46 +02:00
parent b1e8c98ea1
commit 07e16a339f
10 changed files with 128 additions and 73 deletions

View File

@ -303,7 +303,8 @@ begin
.AppendLine(' MVCFramework,')
.AppendLine(' MVCFramework.Logger,')
.AppendLine(' MVCFramework.DotEnv,')
.AppendLine(' MVCFramework.Commons,');
.AppendLine(' MVCFramework.Commons,')
.AppendLine(' MVCFramework.Serializer.Commons,');
if Model.B[TConfigKey.program_ssv_mustache] then
begin
Section
@ -403,7 +404,6 @@ begin
.AppendLine(' MVCFramework.Nullables, MVCFramework.Serializer.Commons;')
.AppendLine
.AppendLine('type')
.AppendLine(' [MVCNameCase(ncCamelCase)]')
.AppendLine(' ' + Model[TConfigKey.entity_classname] + ' = class')
.AppendLine(' private')
.AppendLine(' fID: NullableInt32;')
@ -993,12 +993,19 @@ begin
.AppendLine(' { Enable ReportMemoryLeaksOnShutdown during debug }')
.AppendLine(' // ReportMemoryLeaksOnShutdown := True;')
.AppendLine(' IsMultiThread := True;')
.AppendLine(' // DMVCFramework Specific Configuration ')
.AppendLine(' // When MVCSerializeNulls = True empty nullables and nil are serialized as json null.')
.AppendLine(' // When MVCSerializeNulls = False empty nullables and nil are not serialized at all.')
.AppendLine()
.AppendLine(' // DMVCFramework Specific Configurations ')
.AppendLine(' // When MVCSerializeNulls = True empty nullables and nil are serialized as json null.')
.AppendLine(' // When MVCSerializeNulls = False empty nullables and nil are not serialized at all.')
.AppendLine(' MVCSerializeNulls := True;')
.AppendLine()
.AppendLine(' // MVCNameCaseDefault defines the name case of property names generated by the serializers.')
.AppendLine(' // Possibile values are: ncAsIs, ncUpperCase, ncLowerCase (default), ncCamelCase, ncPascalCase, ncSnakeCase')
.AppendLine(' MVCNameCaseDefault := TMVCNameCase.ncLowerCase;')
.AppendLine()
.AppendLine(' // UseConsoleLogger defines if logs must be emitted to also the console (if available).')
.AppendLine(' UseConsoleLogger := True;')
.AppendLine
.AppendLine()
.AppendLine(' LogI(''** DMVCFramework Server ** build '' + DMVCFRAMEWORK_VERSION);');
if Model.B[TConfigKey.program_dotenv] then

View File

@ -825,10 +825,9 @@ uses
System.NetEncoding,
System.Character,
MVCFramework.Serializer.JsonDataObjects,
MVCFramework.Serializer.Commons,
MVCFramework.Utils,
System.RegularExpressions,
MVCFramework.Logger;
MVCFramework.Logger, MVCFramework.Serializer.Commons;
var
GlobalAppName, GlobalAppPath, GlobalAppExe: string;

View File

@ -47,57 +47,57 @@ type
TDataSetHelper = class helper for TDataSet
public
procedure LoadFromTValue(const Value: TValue;
const aNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase);
function AsJSONArray(FieldNameCase: TMVCNameCase = ncLowerCase): string;
function AsJDOJSONArray(FieldNameCase: TMVCNameCase = ncLowerCase)
const aNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault);
function AsJSONArray(FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault): string;
function AsJDOJSONArray(FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault)
: TJDOJsonArray;
function MetadataAsJSONObject(FieldNameCase: TMVCNameCase = ncLowerCase)
function MetadataAsJSONObject(FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault)
: TJSONObject;
function AsJSONArrayOfValues: TJDOJsonArray;
function AsJSONArrayString: string; deprecated 'Use AsJSONArray';
function AsJSONObject(FieldNameCase: TMVCNameCase = ncLowerCase;
function AsJSONObject(FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault;
const IgnoredFields: TArray<string> = nil): string;
function AsJSONObjectString: string; deprecated 'Use AsJSONObject';
procedure LoadFromJSONObject(const JSONObject: TJSONObject;
const FieldNameCase: TMVCNameCase); overload;
procedure LoadFromJSONObject(const JSONObject: TJSONObject;
const AIgnoredFields: TArray<string> = nil;
const FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
const FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
procedure LoadFromJSONArray(AJSONArray: string;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
procedure LoadFromJSONArray(AJSONArray: TJSONArray;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
procedure LoadJSONArrayFromJSONObjectProperty(PropertyName: string;
JSONObject: string;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
procedure LoadJSONArrayFromJSONObjectProperty(PropertyName: string;
JSONObject: TJSONObject;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
procedure LoadJSONObjectFromJSONObjectProperty(PropertyName: string;
JSONObject: string;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
procedure LoadJSONObjectFromJSONObjectProperty(PropertyName: string;
JSONObject: TJSONObject;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
procedure LoadFromJSONArrayString(AJSONArrayString: string;
AIgnoredFields: TArray<string>;
FieldNameCase: TMVCNameCase = ncLowerCase); overload; deprecated;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload; deprecated;
procedure LoadFromJSONArrayString(AJSONArrayString: string;
FieldNameCase: TMVCNameCase = ncLowerCase); overload;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
procedure LoadFromJSONObjectString(AJSONObjectString: string); overload;
procedure LoadFromJSONObjectString(const JSONObjectString: string;
const IgnoredFields: TArray<string>;
const FieldNameCase: TMVCNameCase = ncLowerCase); overload;
const FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
// procedure LoadJSONArrayFromJSONObjectProperty(const AJSONObjectString: string; const aPropertyName: string;
// const FieldNameCase: TMVCNameCase = ncLowerCase);
// const FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase);
procedure AppendFromJSONArrayString(AJSONArrayString: string); overload;
procedure AppendFromJSONArrayString(AJSONArrayString: string;
AIgnoredFields: TArray<string>;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncLowerCase); overload;
FieldNameCase: TMVCNameCase = TMVCNameCase.ncUseDefault); overload;
function AsObjectList<T: class, constructor>(CloseAfterScroll
: boolean = false; OwnsObjects: boolean = true): TObjectList<T>;
function AsObject<T: class, constructor>(CloseAfterScroll
@ -117,7 +117,7 @@ type
ACloseDataSetAfterScroll: boolean = true);
end;
[MVCNameCase(ncLowerCase)]
[MVCNameCase(ncUseDefault)]
TDataSetHolder = class
private
fDataSet: TDataSet;
@ -191,7 +191,7 @@ begin
lSer := TMVCJsonDataObjectsSerializer.Create;
try
lSer.JsonArrayToDataSet(TJSONArray(Value.AsObject), Self, [],
TMVCNameCase.ncLowerCase);
TMVCNameCase.ncUseDefault);
finally
lSer.Free;
end;
@ -213,7 +213,7 @@ end;
// end;
function TDataSetHelper.AsJDOJSONArray(FieldNameCase
: TMVCNameCase = ncLowerCase): TJDOJsonArray;
: TMVCNameCase = TMVCNameCase.ncUseDefault): TJDOJsonArray;
var
lSerializer: TMVCJsonDataObjectsSerializer;
begin
@ -256,7 +256,7 @@ begin
end;
function TDataSetHelper.AsJSONArray(FieldNameCase
: TMVCNameCase = ncLowerCase): string;
: TMVCNameCase = TMVCNameCase.ncUseDefault): string;
var
lSerializer: IMVCSerializer;
begin
@ -285,7 +285,7 @@ end;
function TDataSetHelper.AsJSONObjectString: string;
begin
Result := AsJSONObject(ncLowerCase);
Result := AsJSONObject(ncUseDefault);
end;
function TDataSetHelper.AsObject<T>(CloseAfterScroll: boolean): T;

View File

@ -568,7 +568,7 @@ begin
try
lJArr := TJDOJsonArray.Create;
JSONArr.Add(lJArr);
lSer.DataSetToJsonArray(TDataSet(Value.AsObject), lJArr, TMVCNameCase.ncLowerCase, []);
lSer.DataSetToJsonArray(TDataSet(Value.AsObject), lJArr, TMVCNameCase.ncUseDefault, []);
finally
lSer.Free;
end
@ -680,7 +680,7 @@ begin
begin
lSer := TMVCJsonDataObjectsSerializer.Create;
try
lSer.DataSetToJsonArray(TDataSet(Value.AsObject), JSONObj.A[name], TMVCNameCase.ncLowerCase, []);
lSer.DataSetToJsonArray(TDataSet(Value.AsObject), JSONObj.A[name], TMVCNameCase.ncUseDefault, []);
finally
lSer.Free;
end

View File

@ -48,7 +48,8 @@ uses
MVCFramework.Commons,
Data.DB,
System.Generics.Collections,
JsonDataObjects, MVCFramework.DuckTyping;
JsonDataObjects,
MVCFramework.DuckTyping;
type
EMVCSerializationException = class(EMVCException)
@ -59,7 +60,7 @@ type
TMVCSerializationType = (stUnknown, stDefault, stProperties, stFields);
TMVCNameCase = (ncAsIs, ncUpperCase, ncLowerCase, ncCamelCase, ncPascalCase, ncSnakeCase);
TMVCNameCase = (ncUseDefault, ncAsIs, ncUpperCase, ncLowerCase, ncCamelCase, ncPascalCase, ncSnakeCase);
TMVCDataType = (dtObject, dtArray);
@ -203,7 +204,7 @@ type
private
{ private declarations }
public
class function ApplyNameCase(const NameCase: TMVCNameCase; const Value: string): string; static;
class function ApplyNameCase(NameCase: TMVCNameCase; const Value: string): string; static; inline;
class function GetKeyName(const AField: TRttiField; const AType: TRttiType): string;
overload; static;
class function GetKeyName(const AProperty: TRttiProperty; const AType: TRttiType): string;
@ -212,9 +213,9 @@ type
class function HasAttribute<T: class>(const AMember: TRttiObject; out AAttribute: T): Boolean;
overload; static;
class function AttributeExists<T: TCustomAttribute>(const AAttributes: TArray<TCustomAttribute>;
out AAttribute: T): Boolean; overload; static;
out AAttribute: T): Boolean; overload; static; inline;
class function AttributeExists<T: TCustomAttribute>(const AAttributes: TArray<TCustomAttribute>)
: Boolean; overload; static;
: Boolean; overload; static; inline;
class procedure EncodeStream(AInput, AOutput: TStream); static;
class procedure DecodeStream(AInput, AOutput: TStream); static;
@ -243,14 +244,14 @@ type
end;
// Well Known Response Objects
[MVCNameCase(ncLowerCase)]
[MVCNameCase(ncUseDefault)]
TMVCResponseBase = class abstract(TInterfacedObject, IMVCResponseData)
protected
function GetMetadata: TMVCStringDictionary; virtual; abstract;
function GetData: TObject; virtual; abstract;
end;
[MVCNameCase(ncLowerCase)]
[MVCNameCase(ncUseDefault)]
TMVCTask = class
private
fID: string;
@ -261,7 +262,7 @@ type
constructor Create(const HREF, ID: string);
end;
[MVCNameCase(ncLowerCase)]
[MVCNameCase(ncUseDefault)]
TMVCAcceptedResponse = class(TMVCResponseBase)
private
fTask: TMVCTask;
@ -272,7 +273,7 @@ type
destructor Destroy; override;
end;
[MVCNameCase(ncLowerCase)]
[MVCNameCase(ncUseDefault)]
TMVCResponseData = class(TMVCResponseBase, IMVCResponseData)
private
fData: TObject;
@ -316,7 +317,7 @@ type
function Add(const Name: string; const Value: TDataset;
const SerializationAction: TMVCDataSetSerializationAction = nil;
const DataSetSerializationType: TMVCDatasetSerializationType = dstAllRecords;
const NameCase: TMVCNameCase = TMVCNameCase.ncLowerCase;
const NameCase: TMVCNameCase = TMVCNameCase.ncUseDefault;
const AIgnoredFields: TMVCIgnoredList = nil): IMVCObjectDictionary; overload;
function TryGetValue(const Name: string; out Value: TObject): Boolean; overload;
function Count: Integer;
@ -378,7 +379,7 @@ type
function Add(const Name: string; const Value: TDataset;
const SerializationAction: TMVCDataSetSerializationAction = nil;
const DataSetSerializationType: TMVCDatasetSerializationType = dstAllRecords;
const NameCase: TMVCNameCase = TMVCNameCase.ncLowerCase;
const NameCase: TMVCNameCase = TMVCNameCase.ncUseDefault;
const AIgnoredFields: TMVCIgnoredList = nil): IMVCObjectDictionary; overload;
function TryGetValue(const Name: string; out Value: TObject): Boolean; overload;
function Count: Integer;
@ -418,6 +419,9 @@ var
/// </example>
gLocalTimeStampAsUTC: Boolean;
var
MVCNameCaseDefault: TMVCNameCase = TMVCNameCase.ncLowerCase;
function DateTimeToISOTimeStamp(const ADateTime: TDateTime): string;
function DateToISODate(const ADate: TDateTime): string;
function TimeToISOTime(const ATime: TTime): string;
@ -439,7 +443,7 @@ function ISODateToDate(const ADate: string): TDate;
function ISOTimeToTime(const ATime: string): TTime;
const
JSONNameLowerCase = ncLowerCase deprecated 'Use MVCNameCaseAttribute(ncLowerCase)';
JSONNameLowerCase = TMVCNameCase.ncLowerCase deprecated 'Use MVCNameCaseAttribute(ncLowerCase)';
JSONNameUpperCase = ncUpperCase deprecated 'Use MVCNameCaseAttribute(ncUpperCase)';
function StrDict: TMVCStringDictionary; overload;
@ -654,36 +658,41 @@ begin
Result := (AAttribute <> nil);
end;
class function TMVCSerializerHelper.ApplyNameCase(const NameCase: TMVCNameCase;
class function TMVCSerializerHelper.ApplyNameCase(NameCase: TMVCNameCase;
const Value: string): string;
begin
if NameCase = TMVCNameCase.ncUseDefault then
begin
NameCase := MVCNameCaseDefault;
end;
case NameCase of
ncUpperCase:
TMVCNameCase.ncUpperCase:
begin
Result := UpperCase(Value);
end;
ncLowerCase:
TMVCNameCase.ncLowerCase:
begin
Result := LowerCase(Value);
end;
ncCamelCase:
TMVCNameCase.ncCamelCase:
begin
Result := CamelCase(Value);
end;
ncPascalCase:
TMVCNameCase.ncPascalCase:
begin
Result := CamelCase(Value, True);
end;
ncSnakeCase:
TMVCNameCase.ncSnakeCase:
begin
Result := SnakeCase(Value);
end;
ncAsIs:
TMVCNameCase.ncAsIs:
begin
Result := Value;
end
else
raise Exception.Create('Invalid NameCase');
raise Exception.Create('Unknown TMVCNameCase: ' + GetEnumName(TypeInfo(TMVCNameCase), Ord(NameCase)));
end;
end;
@ -829,14 +838,14 @@ begin
end;
end;
Attrs := AType.GetAttributes;
for Attr in Attrs do
for Attr in AType.GetAttributes do
begin
if Attr is MVCNameCaseAttribute then
begin
Exit(TMVCSerializerHelper.ApplyNameCase(MVCNameCaseAttribute(Attr).KeyCase, Result));
end;
end;
Result := TMVCSerializerHelper.ApplyNameCase(MVCNameCaseDefault, Result);
end;
class function TMVCSerializerHelper.GetTypeKindAsString(const ATypeKind: TTypeKind): string;

View File

@ -417,7 +417,7 @@ begin
try
if lDataSetHolder.SerializationType = TMVCDatasetSerializationType.dstAllRecords then
begin
lSer.DataSetToJsonArray(lDataSetHolder.Items, lOutObject.A['data'], TMVCNameCase.ncLowerCase, [])
lSer.DataSetToJsonArray(lDataSetHolder.Items, lOutObject.A['data'], TMVCNameCase.ncUseDefault, [])
end
else // single record
begin
@ -426,9 +426,9 @@ begin
raise EMVCException.CreateFmt('DataSet contains %d records - exactly 1 expected',
[lDataSetHolder.Items.RecordCount]);
end;
lDSFields := lSer.GetDataSetFields(lDataSetHolder.Items, [], TMVCNameCase.ncLowerCase);
lDSFields := lSer.GetDataSetFields(lDataSetHolder.Items, [], TMVCNameCase.ncUseDefault);
try
lSer.DataSetToJsonObject(lDataSetHolder.Items, lOutObject.O['data'], TMVCNameCase.ncLowerCase, [],
lSer.DataSetToJsonObject(lDataSetHolder.Items, lOutObject.O['data'], TMVCNameCase.ncUseDefault, [],
lDSFields);
finally
lDSFields.Free;

View File

@ -334,10 +334,10 @@ var
lBuffer: Pointer;
lCurrentArrayItem: TValue;
begin
if SameText(AName, 'RefCount') then
begin
Exit;
end;
// if SameText(AName, 'RefCount') then
// begin
// Exit;
// end;
if AValue.IsEmpty then
begin
@ -704,7 +704,7 @@ begin
begin
Result := TJsonArray.Create;
AJsonDataType := jdtArray;
DataSetToJsonArray(TDataSet(AObject), TJsonArray(Result), TMVCNameCase.ncLowerCase, [],
DataSetToJsonArray(TDataSet(AObject), TJsonArray(Result), TMVCNameCase.ncUseDefault, [],
ADataSetSerializationCallback);
end
else if AObject is TJsonObject then
@ -1693,7 +1693,7 @@ begin
if Assigned(ChildObject) then
begin
if ChildObject is TDataSet then
JsonArrayToDataSet(AJSONObject.A[APropertyName], ChildObject as TDataSet, AIgnored, ncLowerCase)
JsonArrayToDataSet(AJSONObject.A[APropertyName], ChildObject as TDataSet, AIgnored, TMVCNameCase.ncUseDefault)
else if GetTypeSerializers.ContainsKey(ChildObject.ClassInfo) then
begin
GetTypeSerializers.Items[ChildObject.ClassInfo].DeserializeAttribute(AValue, APropertyName, AJSONObject,
@ -2693,6 +2693,15 @@ begin
begin
for Prop in ObjType.GetProperties do
begin
if TMVCSerializerHelper.IsAPropertyToSkip(Prop.Name) then
begin
Continue;
end;
// if Prop.Name = 'RefCount' then
// begin
// Continue;
// end;
{$IFDEF AUTOREFCOUNT}
if TMVCSerializerHelper.IsAPropertyToSkip(Prop.Name) then
@ -3106,7 +3115,7 @@ begin
begin
if Obj is TDataSet then
begin
DataSetToJsonArray(TDataSet(Obj), JSONArray.AddArray, TMVCNameCase.ncLowerCase, nil,nil,);
DataSetToJsonArray(TDataSet(Obj), JSONArray.AddArray, TMVCNameCase.ncUseDefault, nil,nil,);
end
else
begin
@ -3802,7 +3811,7 @@ begin
lSer := TMVCJsonDataObjectsSerializer.Create;
try
JSON.A[KeyName] := TJDOJsonArray.Create;
lSer.DataSetToJsonArray(TDataSet(lValueAsObj), JSON.A[KeyName], TMVCNameCase.ncLowerCase, []);
lSer.DataSetToJsonArray(TDataSet(lValueAsObj), JSON.A[KeyName], TMVCNameCase.ncUseDefault, []);
finally
lSer.Free;
end;

View File

@ -1169,7 +1169,6 @@ type
property OnRouterLog: TMVCRouterLogHandlerProc read fOnRouterLog write fOnRouterLog;
end;
[MVCNameCase(ncLowerCase)]
TMVCErrorResponseItem = class
private
FMessage: string;
@ -1180,8 +1179,6 @@ type
property message: string read FMessage write FMessage;
end;
TMVCBaseResponse = class abstract (TInterfacedObject, IMVCResponse)
protected
function GetMessage: string;virtual; abstract;
@ -1203,7 +1200,6 @@ type
constructor Create; virtual;
end;
[MVCNameCase(ncLowerCase)]
TMVCResponse = class(TMVCBaseResponse)
private
fStatusCode: Integer;
@ -1246,7 +1242,6 @@ type
property ObjectDictionary: IMVCObjectDictionary read GetObjectDictionary write SetObjectDictionary;
end;
[MVCNameCase(ncLowerCase)]
TMVCErrorResponse = class(TMVCResponse)
private
fClassname: string;
@ -4987,7 +4982,7 @@ procedure TMVCRenderer.Render(const ADataSet: TDataSet; const AOwns: Boolean;
const AIgnoredFields: TMVCIgnoredList; const ASerializationType: TMVCDatasetSerializationType;
const ASerializationAction: TMVCDatasetSerializationAction);
begin
Render(ADataSet, AOwns, AIgnoredFields, ncLowerCase, ASerializationType, ASerializationAction);
Render(ADataSet, AOwns, AIgnoredFields, TMVCNameCase.ncLowerCase, ASerializationType, ASerializationAction);
end;
procedure TMVCRenderer.Render(const ADataSet: TDataSet; const AOwns: Boolean;

View File

@ -33,10 +33,11 @@ uses
System.Classes,
MVCFramework,
MVCFramework.Commons,
MVCFramework.Server;
MVCFramework.Server,
MVCFramework.Serializer.Commons;
type
[MVCNameCase(ncAsIs)]
TAppUser = class
strict private
FCod: Integer;

View File

@ -343,6 +343,9 @@ const
var
O: TObjectList<TNote>;
begin
var lSavedMVCNameCase := MVCNameCaseDefault;
MVCNameCaseDefault := ncAsIs;
O := TObjectList<TNote>.Create(True);
try
fSerializer.DeserializeCollection(JSON_PROPERTIES, O, TNote);
@ -358,6 +361,8 @@ begin
finally
O.Free;
end;
MVCNameCaseDefault := lSavedMVCNameCase;
end;
procedure TMVCTestSerializerJsonDataObjects.TestDeserializeDataSet;
@ -493,6 +498,9 @@ const
var
O: TEntity;
begin
var lSavedMVCNameCase := MVCNameCaseDefault;
MVCNameCaseDefault := ncAsIs;
O := TEntity.Create;
try
fSerializer.DeserializeObject(JSON_PROPERTIES, O);
@ -508,6 +516,8 @@ begin
finally
O.Free;
end;
MVCNameCaseDefault := lSavedMVCNameCase;
end;
procedure TMVCTestSerializerJsonDataObjects.TestDeserializeEntityCustomMemberSerializer;
@ -517,6 +527,9 @@ const
var
O: TSale;
begin
var lSavedMVCNameCase := MVCNameCaseDefault;
MVCNameCaseDefault := ncAsIs;
O := TSale.Create;
try
fSerializer.DeserializeObject(JSON, O);
@ -528,6 +541,8 @@ begin
finally
O.Free;
end;
MVCNameCaseDefault := lSavedMVCNameCase;
end;
procedure TMVCTestSerializerJsonDataObjects.TestDeserializeEntityCustomSerializer;
@ -553,6 +568,9 @@ const
var
O: TEntityCustomWithNullables;
begin
var lSavedMVCNameCase := MVCNameCaseDefault;
MVCNameCaseDefault := ncAsIs;
O := TEntityCustomWithNullables.Create;
try
fSerializer.DeserializeObject(JSON, O);
@ -562,6 +580,8 @@ begin
finally
O.Free;
end;
MVCNameCaseDefault := lSavedMVCNameCase
end;
procedure TMVCTestSerializerJsonDataObjects.TestDeserializeEntitySerializationType;
@ -573,6 +593,9 @@ var
OFields: TEntitySerializeFields;
OProperties: TEntitySerializeProperties;
begin
var lSavedMVCNameCase := MVCNameCaseDefault;
MVCNameCaseDefault := ncAsIs;
OFields := TEntitySerializeFields.Create;
try
fSerializer.DeserializeObject(JSON_FIELDS, OFields);
@ -592,6 +615,8 @@ begin
finally
OProperties.Free;
end;
MVCNameCaseDefault := lSavedMVCNameCase;
end;
procedure TMVCTestSerializerJsonDataObjects.TestDeserializeEntityWithArray;
@ -612,6 +637,9 @@ const
var
O: TEntityWithArray;
begin
var lSavedMVCNameCase := MVCNameCaseDefault;
MVCNameCaseDefault := ncAsIs;
O := TEntityWithArray.Create;
try
fSerializer.DeserializeObject(JSON_WITH_ARRAY, O);
@ -619,6 +647,7 @@ begin
finally
O.Free;
end;
MVCNameCaseDefault := lSavedMVCNameCase;
end;
procedure TMVCTestSerializerJsonDataObjects.TestDeserializeOwnedProperty_WithPropertyUnassigned_JSONExists;
@ -990,6 +1019,8 @@ var
lObj1: TMyObject;
lSer: string;
begin
var lSavedMVCNameCase := MVCNameCaseDefault;
MVCNameCaseDefault := ncAsIs;
lObj1 := GetMyObject;
try
lSer := fSerializer.SerializeObject(lObj1);
@ -1019,6 +1050,7 @@ begin
finally
lJObj.Free;
end;
MVCNameCaseDefault := lSavedMVCNameCase
end;
procedure TMVCTestSerializerJsonDataObjects.TestSerializeCollection;
@ -1505,6 +1537,8 @@ var
lStr: string;
lJObj: TJsonObject;
begin
var lSavedMVCNameCase := MVCNameCaseDefault;
MVCNameCaseDefault := ncAsIs;
lPeople := TPeople.Create;
try
lPerson := TPerson.Create;
@ -1525,6 +1559,7 @@ begin
finally
lPeople.Free;
end;
MVCNameCaseDefault := lSavedMVCNameCase;
end;
procedure TMVCTestSerializerJsonDataObjects.TestSerializeListWithNulls2;