#1 2015-12-02 04:09:06

igors233
Member
Registered: 2012-09-10
Posts: 234

JSONToObject enum improvement

JSONToObject will fail if it encounters invalid enumaration (-1) when reading previously saved object.

example:
      tkEnumeration: begin
        if wasString then begin // in case enum stored as string
          V := P^.PropType^.EnumBaseType^.GetEnumNameValue(PropValue);
          if V<0 then
            exit;

However ObjectToJSON does save object with such enum and that can be potentially dangerous since object is left in inconsistent state (half loaded) and if that object contains child objects they could be partly loaded.
My suggestion is to either:
a) introduce j2oIgnoreUnknownEnum to TJSONToObjectOption and simply continue loading of such object
b) recursively go up to list of created objects and delete them all (not just the last offending one). This could be useful for other fail situations as well, when object is only partially loaded. This of course could be configurable.

Offline

#2 2015-12-02 12:37:16

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: JSONToObject enum improvement

I've implemented suggestion a).

See http://synopse.info/fossil/info/bc96e7fb50

Thanks for the feedback!

Offline

#3 2015-12-02 22:35:20

igors233
Member
Registered: 2012-09-10
Posts: 234

Re: JSONToObject enum improvement

Wow, that was fast wink
Thank you very much for this and whole mORMot you've been doing.

Offline

Board footer

Powered by FluxBB