You are not logged in.
The following code.
type
{$RTTI EXPLICIT PROPERTIES([vcPublished]) FIELDS([vcPublic]) METHODS([])}
TReq = packed record
id: Cardinal;
desc: UTF8String;
amount: Double;
memo: UTF8String;
end;
{$RTTI EXPLICIT METHODS([]) FIELDS([]) PROPERTIES([])}
var
req: TReq;
s: UTF8String;
begin
with req do begin
id := 1000;
desc := 'test';
end;
SaveJson(req, TypeInfo(TReq), TEXTWRITEROPTIONS_SETASTEXT[False], s, [woDontStoreVoid]);
WriteLn(s);
end.The output is
{"id":1000,"desc":"test","amount":0,"memo":""}instead of
{"id":1000,"desc":"test"}I'm using the latest trunk.
Offline
I understand the confusion.
TTextWriterWriteObjectOptions are for class instances - as stated by the "WriteObject" naming, and the documentation.
So woDontStoreVoid won't work on record fields.
What you expect is [woDontStoreDefault] instead of TEXTWRITEROPTIONS_SETASTEXT[False].
Offline
Thank you for your guidance. Everything works fine now when the above record is changed to class.
Offline
As far as I know, this method works.
s:=SaveJson(req, 'TReq',[twoIgnoreDefaultInRecord]);Offline