#1 2021-08-25 12:54:28

wxinix
Member
Registered: 2020-09-07
Posts: 121

mORMot2 ObjectLoadJSON question

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

#2 2021-08-25 14:17:30

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

Re: mORMot2 ObjectLoadJSON question

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

#3 2021-08-25 15:33:27

wxinix
Member
Registered: 2020-09-07
Posts: 121

Re: mORMot2 ObjectLoadJSON question

@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

#4 2021-08-25 20:13:08

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

Re: mORMot2 ObjectLoadJSON question

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

#5 2021-08-25 20:29:37

wxinix
Member
Registered: 2020-09-07
Posts: 121

Re: mORMot2 ObjectLoadJSON question

Thank you very much @ab. 

It works!

Offline

Board footer

Powered by FluxBB