Skip to content

Commit

Permalink
https://github.com/danieleteti/delphimvcframework/issues/792
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Dec 22, 2024
1 parent 2bf917f commit 048e6f1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sources/MVCFramework.Serializer.JsonDataObjects.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,11 @@ procedure TMVCJsonDataObjectsSerializer.JSONObjectPropertyToTValue(AJSONObject:
LClazz: TClass;
lValueTypeInfo: PTypeInfo;
begin
if AJSONObject = nil then
begin
Exit;
end;

case AJSONObject[APropertyName].Typ of
jdtNone:
Exit;
Expand Down
39 changes: 39 additions & 0 deletions unittests/general/Several/Serializers.JsonDataObjectsTestU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ TMVCTestSerializerJsonDataObjects = class(TObject)
[Test]
[Category('serializers')]
procedure TestDeserializeOwnedProperty_WithPropertyUnassigned_JSONExists_Polimorphic;

[Test]
[Category('issues')]
procedure TestIssue792;
end;

TMVCEntityCustomSerializerJsonDataObjects = class(TInterfacedObject, IMVCTypeSerializer)
Expand Down Expand Up @@ -216,6 +220,15 @@ TMVCNullableIntegerSerializerJsonDataObjects = class(TInterfacedObject, IMVCTy
/// </summary>
TNestedGenericEntity = TGenericEntity<TGenericEntity<TNote>>;

TMyObj = class
private
fName: string;
fNumber: integer;
public
property Name: string read FName write FName;
property Number: integer read FNumber write FNumber;
end;

implementation

uses
Expand Down Expand Up @@ -917,6 +930,32 @@ procedure TMVCTestSerializerJsonDataObjects.TestDoNotSerializeDoNotDeSerialize;

end;

procedure TMVCTestSerializerJsonDataObjects.TestIssue792;
var
lMyObj: TMyObj;
lSer: IMVCSerializer;
begin
lMyObj := TMyObj.Create;
try
lMyObj.Name := 'will be changed';
lSer := TMVCJsonDataObjectsSerializer.Create();
lSer.DeserializeObject('{ "dataobject" : { "name" : "Daniele", "number" : 123 }}', lMyObj, stDefault, nil, 'dataobject');
Assert.Contains(lSer.SerializeObject(lMyObj), 'Daniele');
finally
lMyObj.Free;
end;

lMyObj := TMyObj.Create;
try
lSer := TMVCJsonDataObjectsSerializer.Create();
lMyObj.Name := 'the untouchable';
lSer.DeserializeObject('{ "dataobject" : null}', lMyObj, stDefault, nil, 'dataobject');
Assert.Contains(lSer.SerializeObject(lMyObj), 'the untouchable');
finally
lMyObj.Free;
end;
end;

procedure TMVCTestSerializerJsonDataObjects.TestSerializeAllNullableTypes;
var
lObj1, lObj2: BusinessObjectsU.TNullablesTest;
Expand Down

0 comments on commit 048e6f1

Please sign in to comment.