#1 2024-09-01 15:34:26

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

array of Variant as a parameter in mormot http function requests

Array of variant does not work as a parameter when calling a http interface function of a mormot http server.
I remember I read somewhere that the solution is to transform it to tdocvariant and send it as json

Is that correct?
If so, is there a way to do replace it fast?
I can probably replace the array of Variant with an rawutf8 parameter in the functions and then:
a) use _arr(['aaa',1,5]) to get the a json rawutf8 parameter
b) use _JsonFast or DocList functions inside the called http inteface function to get the array members

Do you propose something else?

Last edited by dcoun (2024-09-01 15:34:47)

Offline

#2 2024-09-01 17:20:33

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

Re: array of Variant as a parameter in mormot http function requests

You mean as parameter of SOA service definition with interfaces?

_ArrFast() is certainly the way to go, if you just want to send an array of values..
And it returns a variant, which will be properly serialized and unserialized of the HTTP connection as a JSON array.
Don't use a RawUtf8 parameter: it would be serialized as a JSON string, not a JSON array.
Using a variant parameter is the way to go.

Offline

#3 2024-09-01 17:23:23

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: array of Variant as a parameter in mormot http function requests

Thank you a lot @ab.

Offline

#4 2024-09-01 17:57:25

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

Re: array of Variant as a parameter in mormot http function requests

Of course, if you prefer, you could use a IDocList parameter.
Perhaps it makes more sense for the end-user of the code: it would be impossible to write anything but a JSON array.

Offline

#5 2024-09-02 10:04:58

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: array of Variant as a parameter in mormot http function requests

in case I have a json rawutf8 string (e.g. from a recordsavejson ) when is better to use rawjson and when variant as a parameter type when calling an interface function in a mormot http server?

Offline

#6 2024-09-02 19:49:50

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

Re: array of Variant as a parameter in mormot http function requests

RawJson is indeed the way to go, if you have an already formatted JSON content.

Offline

Board footer

Powered by FluxBB