Re: [fpc-devel] restbase.pp LoadFromJSON calling StopRecordPropertyChanges;
On Sun, 15 Jan 2023, Wayne Sherman wrote: On Sun, Jan 15, 2023 at 9:24 AM Michael Van Canneyt wrote: On Sat, 14 Jan 2023, Wayne Sherman wrote: I see a couple of problems TBaseObject.SaveToJSON 1) TBaseObject.SaveToJSON cannot distinguish properties that are part of the REST protocol from properties that are not part of it. It only knows that properties which have been modified are part of the rest protocol, but properties which have not been modified might be part of the REST protocol or might not be. For example, a client receives a JSON object from a server (via LoadFromJSON) and wants to persist the complete JSON object to disk, database, or send it to another server. But, at present, there is no way to save all the properties that are part of the REST protocol without getting contaminated with non-REST properties. The non-REST properties will never be marked as changed, so they will not be saved. LoadFromJSON calls StartRecordPropertyChanges and StopRecordPropertyChanges. Both of these destroy the change records. At present, there is no opportunity to save modified records after loading. If that was fixed I think it would be a step in the right direction. It seems to me we're talking cross-purpose. From my point of view, the code works as designed. It has been in use in production since many years (in fact, since it was committed to FPC). Can you please make a small example that demonstrates the problem you are experiencing, so I can look at it ? Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] restbase.pp LoadFromJSON calling StopRecordPropertyChanges;
On Sun, Jan 15, 2023 at 9:24 AM Michael Van Canneyt wrote: > On Sat, 14 Jan 2023, Wayne Sherman wrote: > > > I see a couple of problems TBaseObject.SaveToJSON > > > > 1) TBaseObject.SaveToJSON cannot distinguish properties that are part > > of the REST protocol from properties that are not part of it. It only > > knows that properties which have been modified are part of the rest > > protocol, but properties which have not been modified might be part of > > the REST protocol or might not be. For example, a client receives a > > JSON object from a server (via LoadFromJSON) and wants to persist the > > complete JSON object to disk, database, or send it to another server. > > But, at present, there is no way to save all the properties that are > > part of the REST protocol without getting contaminated with non-REST > > properties. > > The non-REST properties will never be marked as changed, so they will not be > saved. LoadFromJSON calls StartRecordPropertyChanges and StopRecordPropertyChanges. Both of these destroy the change records. At present, there is no opportunity to save modified records after loading. If that was fixed I think it would be a step in the right direction. Ref: https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-web/src/base/restbase.pp#L1148 Taking a step further, it would be advantageous if TBaseObject and descendants know specifically which of their properties are REST protocol properties independent of whether they have been modified or not. For example, if I want to dump the JSON for an empty object to see the fields, I would like to do this: KeepNote := TNote.Create(nil); //Google Keep Note KeepNote.SaveAsJSON(saveAllProperties); { "name": "", "createTime": "", "updateTime": "", "trashTime": "", "trashed": false, "attachments": [ { } ], "permissions": [ { } ], "title": "", "body": { } } ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] restbase.pp LoadFromJSON calling StopRecordPropertyChanges;
On Sat, 14 Jan 2023, Wayne Sherman wrote: I see a couple of problems TBaseObject.SaveToJSON 1) TBaseObject.SaveToJSON cannot distinguish properties that are part of the REST protocol from properties that are not part of it. It only knows that properties which have been modified are part of the rest protocol, but properties which have not been modified might be part of the REST protocol or might not be. For example, a client receives a JSON object from a server (via LoadFromJSON) and wants to persist the complete JSON object to disk, database, or send it to another server. But, at present, there is no way to save all the properties that are part of the REST protocol without getting contaminated with non-REST properties. The non-REST properties will never be marked as changed, so they will not be saved. 2) Lack of control. With TBaseObject.SaveToJSON it would be nice to control what is saved (Save all REST properties, or Save modified REST properties). It should be easy to add a flag for that. Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel