How to get JSON, which contains only Name and Flags?
TUser = class
private
FName: string;
FFlags: UInt32;
FFields: UInt32;
FCreated: TDateTime;
public
property Name: string read FName write FName;
property Flags: UInt32 read FFlags write FFlags;
property Fields: UInt32 read FFields write FFields;
property Created: TDateTime read FCreated write FCreated;
constructor Create;
end;
Usually is used all fields of this class:
var
User: TUser
sJson: string;
sJson := User.AsJson;
but sometimes I needed a JSON with Name and Flags fields only. Currently, to get such JSON I use such code:
var
User: TUser
usr: ISuperObject;
sJson: string;
usr := SO(User.AsJson);
usr.Remove('Fields');
usr.Remove('Created');
sJson := usr.AsJSON;
But I think is not optimal code (actually in real code I have 15 fields and need to remove 12). How to do that faster?
Updated (another method):
May be this will be more faster and useful for my purpose?
usr := SO('');
usr.S['Name'] := User.Name;
usr.I['Flags'] := User.Flags;
sJson := usr.AsJSON;
Thanks to the @NasreddineGalfout I'm found that is it possible with Neon JSON library. With INeonConfiguration I can select public or published or protected (or any combination) property fields that should be serialized. And is it what I need. Moreover deserializing with Neon is 2x much faster than with XSuperObject.