Michael wrote:
> >> Because there may be other published properties that are not part of the
> >> REST protocol. You may for instance decide to add published properties to a
> >> base class that describe where to save the object in a local database.

Wayne wrote:
> > Ok, that clears up that.  If I understand correctly, the behavior
> > should be as follows:
> >
> > (restbase.pp)
> > In TBaseObject descendants, SaveToJSON only saves object properties
> > defined directly in the final descendant class and none of the
> > properties of parent classes.  This is implemented by only marking
> > properties as modified that are defined directly in the final
> > descendant class and skipping properties of all parent classes (which
> > always appear to be unmodified, and thus not saved).  This prevents
> > properties which are not part of the REST protocol from contaminating
> > the generated JSON.  It follows that REST protocol properties should
> > always be defined in the final TBaseObject descendant class (and not
> > in any base or intermediate classes).

Michael wrote:
> While in practice most REST classes will be the final classes,
> it should be possible to support inheritance in rest classes,
> that is why the 'ParentPropertyCount' exists and is taken into account.

My summary above is incorrect.  How about this?:

In TBaseObject descendants, SaveToJSON only saves object properties
which have had their properties marked as modified using
MarkPropertyChanged (modified flags are stored internally using
TBits).  Properties which have not been marked as modified will not be
saved to JSON.  This prevents properties which are not part of the
REST protocol from contaminating the generated JSON.

Auto generated code that defines TBaseObject descendant classes
declares properties with index specifiers and setter methods that call
MarkPropertyChanged.  When a property is changed in these auto
generated classes, that property will end up in the output of
SaveToJSON.  Properties which are a valid part of the REST protocol,
but which have not been changed are not included in the generated
JSON.

Properties can be defined in a TBaseObject final descendant class or
parent classes and be included in the JSON output (as long as
MarkPropertyChanged has been called with the corresponding index for
that property).
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to