On Sat, 14 Jan 2023, Wayne Sherman wrote:

On Sat, Jan 14, 2023 at 12:36 PM Michael Van Canneyt wrote:
On Sat, 14 Jan 2023, Wayne Sherman wrote:
On Sat, Jan 14, 2023 at 10:34 AM Michael Van Canneyt wrote:
On Sat, 14 Jan 2023, Wayne Sherman wrote:
2) Doesn't each object already have the parent properties included in
its own properties by inheritance?

Why this question ?
An object does not know the property count of the parent.

True, but why does it need to know the property count of the parent?

 TBaseClass = class
 private
   FField1: integer;
 protected
   FPropModifiedFlags: TBits;
 published
   property Field1: integer read FField1 write FField1;
 end;

GetTypeData(TBaseClass.ClassInfo)^.PropCount = 1

 TDescendant = class(TBaseClass)
 private
   FField2: integer;
 published
   property Field2: integer read FField2 write FField2;
 end;

GetTypeData(TDescendant.ClassInfo)^.PropCount = 2

TDescendant has two properties (one inherited and one declared
directly) and let's say it can record if any of the properties have
been modified.  So why does it have to know about the number of
properties it inherited vs the properties it declares directly?

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.

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).


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.

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to