Jump to content
RaelB

Is it possible to skip a field/property when using TJSON.ObjectToJsonObject?

Recommended Posts

Is using "TJSON.ObjectToJsonObject" to convert an object into a TJSONValue (and ultimately into a string).

Is it possible for this conversion to leave out a specific field/fields, for e.g. using some type of attribute?

 

For example:

  TPersistItem = class(TPersistent)
  private
    FChangeStatus: TChangeStatus;
    FId: Variant;
    FLoading: Boolean;
    procedure SetId(const Value: Variant);
  protected
...
    procedure SetChangeStatus(const Value: TChangeStatus);
  public
...
  published
    property ChangeStatus: TChangeStatus read FChangeStatus write SetChangeStatus;
    property Id: Variant read FId write SetId;
  end;

I don't want fields "ChangeStatus" and "Loading" to be included in the result.

 

Thanks

Share this post


Link to post

The attribute you are looking for is JSONMarshalled:

TPersistItem = class(TPersistent)
  private
    [JSONMarshalled(False)]
    FChangeStatus: TChangeStatus;
    FId: Variant;
    [JSONMarshalled(False)]
    FLoading: Boolean;
    procedure SetId(const Value: Variant);
  protected

Make sure to have REST.Json.Types in your uses clause.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×