[fpc-devel] restbase.pp LoadFromJSON calling StopRecordPropertyChanges;
Wayne Sherman
wsherman at gmail.com
Mon Jan 16 03:04:39 CET 2023
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": { }
}
More information about the fpc-devel
mailing list