#1 2021-04-06 09:27:02

squirrel
Member
Registered: 2015-08-13
Posts: 155

Json Parsing issue

A 3rd party logged an issue when consuming one of my rest server's functions.  I tested and confirmed it on Mormot 1.18.6261.  Not sure how to resolve it.  Any suggestions would be welcome.

In my interfaces, I use the following type as an input parameter:

  type TStringDataSet = array of TStringDynArray;
...
  function Test(const ID: Integer; const Data: TStringDataSet): TServiceCustomAnswer;

When a POST is done using the following json body, the call succeeds and the data is correctly parsed and handled:

{"Data": [["ItemA1", "ItemA2"],["ItemB1","ItemB2"]], "ID":12}

However, when the json is formatted to include either a line break or spaces between the opening square bracket of Data and its first item, a 406 Not Acceptable error is returned.  The json is still valid.  Sample json causing the issue:

{"Data": [
["ItemA1", "ItemA2"],["ItemB1","ItemB2"]], "ID":12}

... or ...

{"Data": [ ["ItemA1", "ItemA2"],["ItemB1","ItemB2"]], "ID":12}

Is this something that the mormot parser should be able to handle, or is it something that I'll need a custom serializer for?

Offline

#2 2021-04-06 10:00:49

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

Re: Json Parsing issue

Could you debug a little bit and see where is the issue may be?

It should indeed parse such JSON.
I guess there is a missing GotoNextNotSpace() call somewhere in mormot.core.json.

Offline

#3 2021-04-06 10:18:05

squirrel
Member
Registered: 2015-08-13
Posts: 155

Re: Json Parsing issue

Thanks @ab, I'll try to find it.  It looks like the issue is in SynCommons.pas in the function TDynArray.LoadFromJSON function (around line 50270).  I'll try to isolate it further and provide a more precise test scenario.

in mORMot.pas, in function TServiceMethodExecute.ExecuteJson at line 60667 the following code is called:

smvDynArray: begin
          Par := fDynArrays[IndexVar].Wrapper.LoadFromJSON(Par);

for the correct json, Par has a value, and for the incorrect json, Par is nil.  In this scenario, the Par value that gets sent to LoadFromJSON looks like this when the function succeeds:

' [["ItemA1", "ItemA2"],["ItemB1","ItemB2"]], "ID'

and like this when it fails:

' [ ["ItemA1", "ItemA2"],["ItemB1","ItemB2"]], "ID'

Last edited by squirrel (2021-04-06 10:24:36)

Offline

#4 2021-04-06 10:30:16

squirrel
Member
Registered: 2015-08-13
Posts: 155

Re: Json Parsing issue

It looks like another GotoNextNotSpace() might be needed in SynCommons.pas in the function TDynArray.LoadFromJSON function before line 50300, since that is where it gets the space value instead of the next [ character.  Unfortunately I dont know the code well enough to know the impact of changes there.

Interesting is that in all scenarios, JSONArrayCount return the correct count.

Last edited by squirrel (2021-04-06 10:39:00)

Offline

#5 2021-04-06 10:41:15

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

Re: Json Parsing issue

Please check https://synopse.info/fossil/info/6bb518fb77

mORMot 2 is not concerned I guess - its TJsonParserContext.ParseArray() method in mormot.core.json.pas seems correct with such input.

Offline

#6 2021-04-06 10:48:14

squirrel
Member
Registered: 2015-08-13
Posts: 155

Re: Json Parsing issue

That works perfectly :-)

Thanks @ab.  This is seriously impressive support.

Offline

Board footer

Powered by FluxBB