You are not logged in.
Pages: 1
Given the following record definition:
TSegment = class(TSQLRecord)
strict private
FID: Int64;
FAttrs: Variant;
published
property Attrs: Variant read FAttrs write FAttrs;
end;
And the following JSON string:
LJSON := '{ "RowID": 1, "Attrs": {"SegmentID": "1976-113", "From":"LEXINGTON AV/72 ST","To":"LEXINGTON AV/57 ST"} }'
ObjectLoadJSON (LSegment, LJSON, nil, [jpoHandleCustomVariants]) would return False, indicating invalid JSON format. By debugging, it shows that the parsing broke at "Attrs" - when the parser expects its value to be double quoted.
In other words, if the value of a Variant field is NOT DOUBLE QUOTED, ObjectLoadJSON would fail.
Note: ObjectLoadJSON had been working no problem with early mORMot2 (before June 2021). I suspect some changes introduced to mormot.core.json changed the behavior of ObjectLoadJSON.
Is this an intentional design, or a potential bug?
Thanks.
Last edited by wxinix (2021-08-25 12:56:54)
Offline
I am not able to reproduce your problem about the Attrs field itself.
But your sample would fail for sure, because your JSON has a "RowID" field which doesn't exist as property in TSegment.
If you add the jpoIgnoreUnknownProperty option, this "RowID" field is ignored and the parsing is done.
I have added a regression test about it, and it does pass on my side with Delphi and FPC 3.2.
See https://github.com/synopse/mORMot2/comm … 6ab7001336
Offline
@ab, many thanks for your feedback.
To explain things better, I created a project for you to replicate the issue I encountered. You can download it from here
https://gist.github.com/wxinix/d9c41954 … 391f7b8aaa
Last edited by wxinix (2021-08-25 20:30:54)
Offline
You are right.
The issue is not with a plain TPersistent, but with a TOrm class and ObjectLoadJson().
There was a regression when we used the ORM serialization to be called by ObjectLoadJson().
It should be fixed now.
Thanks for the feedback!
Offline
Thank you very much @ab.
It works!
Offline
Pages: 1