#1 2017-01-18 08:52:05

jaclas
Member
Registered: 2014-09-12
Posts: 215

Return RawJSON parameter in interfaced service and decode error

I have server based on interfaced services.
In service I have method:

    function GetAnnouncementList(out aAnnouncementList: TAnnouncementDataList): Integer;

where:


  TAnnouncementDataList = TArray<RAnnouncementData>;

  RAnnouncementData = record
    UUID : TAnnouncementUUID;
    ReleaseTimestamp: TUnixTimestampUTC;
    DeadTimestamp : TUnixTimestampUTC;
    Topic: RawUTF8;
    ContentsType: SmallInt;
    TagList : RawJSON;   <------------------------------------------ this is problematic
    DemoVersionMode : AnsiChar;
    PersonKind : AnsiChar;
  end;

On client side I get this array like:

{"result":[[{"UUID":"16551D01-CA15-4B32-BDFB-F5D0BDDA42E7","ReleaseTimestamp":1484210095,"DeadTimestamp":1486767600,"Topic":"Msg from: 2017-01-12 09:34:54","ContentsType":66,
"TagList":"{"Tag":["11","22","33","44"]}","DemoVersionMode":76,"PersonKind":78},{"UUID":"FB5A930F-3D3C-4395-B4AC-81CA639E490C","ReleaseTimestamp":1484210097,"DeadTimestamp":1486767600,"Topic":"Msg from: 2017-01-12 09:34:57","ContentsType":66,
"TagList":"{"Tag":["11","22","33","44"]}","DemoVersionMode":76,"PersonKind":78}],2]}

Pay attention that TagList has quotes around: 

--->"{"Tag":["11","22","33","44"]}"<---

and client raise exception EInterfaceFactoryException on decoding this:

''Invalid returned JSON content: expects {result:...}, got {"result~~[[{"UUID":"16551D01-CA15-4B32-BDFB-F5D0BDDA42E7","ReleaseTimestamp":1484210095,"DeadTimestamp":1486767600,"Topic":"Wiadomość z chwili: 2017-01-12 09:34:54","ContentsType":66,"TagList":"{"Tag":["11","22","33","44"]}","DemoVersionMode":76,"PersonKind":78},{"UUID":"FB5A930F-3D3C-4395-B4AC-81CA639E490C","ReleaseTimestamp":1484210097,"DeadTimestamp":1486767600,"Topic":"Wiadomość z chwili: 2017-01-12 09:34:57","ContentsType":66,"TagList":"{"Tag":["11","22","33","44"]}","DemoVersionMode":76,"PersonKind":78}],2]}''

I generate the JSON in business code on the server side and I want to send it to the client.

What am I doing wrong? How can I do this right?

Last edited by jaclas (2017-01-18 08:53:40)

Offline

#2 2017-01-18 12:04:40

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Return RawJSON parameter in interfaced service and decode error

Hi, experiment to return the method as boolean.

Offline

#3 2017-01-18 12:17:46

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

Re: Return RawJSON parameter in interfaced service and decode error

1. Define your record as packed.
2. Try with text registration of the record layout.
3. Or use a variant for the field, to store a TDocVariant content.

Offline

#4 2017-01-18 12:50:26

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Return RawJSON parameter in interfaced service and decode error

Problem is no with record, but with field of type RawJSON that is coded with additional quotes and on client side decoding of server response raise error. Without this field call is sucessful.

{"UUID":"16551D01-CA15-4B32-BDFB-F5D0BDDA42E7",
"ReleaseTimestamp":1484210095,
"DeadTimestamp":1486767600,
"Topic":"Msg from: 2017-01-12 09:34:54",
"ContentsType":66,
"TagList":"{"Tag":["11","22","33","44"]}",  <---- see this, JSON parser not decoding this strange item
"DemoVersionMode":76,
"PersonKind":78}}

It seems to me that the type of RawJSON should be wrapped (be escaped).

Last edited by jaclas (2017-01-18 13:14:10)

Offline

#5 2017-01-18 13:38:25

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: Return RawJSON parameter in interfaced service and decode error

If you change the type RawJSON to RawUTF8?

Offline

#6 2017-01-18 14:52:00

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

Re: Return RawJSON parameter in interfaced service and decode error

1. Define your record as packed.
2. Try with text registration of the record layout.
3. Or use a variant for the field, to store a TDocVariant content.

Offline

#7 2017-01-18 21:14:33

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Return RawJSON parameter in interfaced service and decode error

Junior/RO wrote:

If you change the type RawJSON to RawUTF8?

It helped (escaping string in response), thx.
But I don't understand what is the type of RawJSON?

Offline

#8 2017-01-19 08:51:22

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

Re: Return RawJSON parameter in interfaced service and decode error

There was a bug in TJSONCustomParserRTTI.WriteOneLevel.

Please check http://synopse.info/fossil/info/a43c1620e1

Offline

#9 2017-01-19 12:10:48

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Return RawJSON parameter in interfaced service and decode error

Thanks! But why do you paste three point list for me? ;-)

Offline

#10 2017-01-19 13:45:02

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

Re: Return RawJSON parameter in interfaced service and decode error

Because you did not try those three points...
At that time, it was not clear to me that there was a bug!
smile

Offline

#11 2017-01-19 15:49:35

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Return RawJSON parameter in interfaced service and decode error

I knew that these points was blind ;-P

Offline

Board footer

Powered by FluxBB