mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
added support to serialize json null value as nil in object property
added relative test TestJSONObjectToObjectWithNullInJSONString
This commit is contained in:
parent
ef8e90f087
commit
3f0eb0d040
@ -2314,7 +2314,12 @@ begin
|
||||
o := _field.GetValue(TObject(AObject)).AsObject;
|
||||
if Assigned(o) then
|
||||
begin
|
||||
if o is TStream then
|
||||
if jvalue is TJSONNull then
|
||||
begin
|
||||
FreeAndNil(o);
|
||||
_field.SetValue(AObject, nil);
|
||||
end
|
||||
else if o is TStream then
|
||||
begin
|
||||
if jvalue is TJSONString then
|
||||
begin
|
||||
|
@ -61,6 +61,7 @@ type
|
||||
procedure TestJSONArrayToObjectListNoGenerics;
|
||||
procedure TestJSONArrayToObjectListNoGenericsWrappedList;
|
||||
procedure TestCheckMapperSerializeAsStringIsEmptyStrIfObjIsNil;
|
||||
procedure TestJSONObjectToObjectWithNullInJSONString;
|
||||
|
||||
end;
|
||||
|
||||
@ -566,6 +567,17 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestMappers.TestJSONObjectToObjectWithNullInJSONString;
|
||||
var
|
||||
LJSONObject: string;
|
||||
Obj: TMyStreamObject;
|
||||
begin
|
||||
LJSONObject := '{"ImageStream":null}';
|
||||
Obj := Mapper.JSONObjectStringToObject<TMyStreamObject>(LJSONObject);
|
||||
CheckNull(Obj.ImageStream);
|
||||
Obj.Free;
|
||||
end;
|
||||
|
||||
procedure TTestMappers.TestLoadJSONObjectToObjectAndBack;
|
||||
var
|
||||
Obj: TMyObject;
|
||||
|
Loading…
Reference in New Issue
Block a user