Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SkipyEmptyValues doesn't serialize correctly null object property value #154

Open
bobprog72 opened this issue Jan 2, 2025 · 0 comments
Open

Comments

@bobprog72
Copy link

bobprog72 commented Jan 2, 2025

testskip.zip

Model

type
TChildObject = class
private
FchildProp: string;
public
property childProp: string read FchildProp write FchildProp;
end;

type
TMainObject = class
private
FmainProp: string;
Fchild: TChildObject;
public
property mainProp: string read FmainProp write FmainProp;
property child: TChildObject read Fchild write FChild; <<<------------
end;


IMPLEMENTATION

function TTestResource.Test: string;
begin
var LMain := TMainObject.Create;
LMain.mainProp := 'mainProp';

var LJO := TJSONObject.Create;
try
LJO.FromObject( LMain );

ForceDirectories( 'c:\tteemmpp' );
TFile.WriteAllText( 'c:\tteemmpp\xxx.json', LJO.ToJSON );

finally
LJO.Free;
LMain.Free;
end;
end;


RESULT (xxx.json)

{"mainProp":"mainProp","child":null}

The "child" property appears with null value. I think that with SkipEmptyValues=true the property must not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant