added support to serialize json null value as nil in object property

added relative test TestJSONObjectToObjectWithNullInJSONString
This commit is contained in:
spinettaro 2016-10-26 14:42:45 +02:00
parent ef8e90f087
commit 3f0eb0d040
2 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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;