You are not logged in.
Hi I have a service-method server and I am trying to get the json without the Result: wrapper. The problem is that even with using the ResultAsJsonObjectWithoutResult:=true; its not working. Can anyone help me.
Offline
This ResultAsJsonObjectWithoutResult attribute is tested during the regression tests, so I guess you are not doing it properly.
Note that it depends on the InstanceCreation mode, which should be sicSingle or sicShared by definition.
Please refine "it is not working".
And try to debug a little bit more on your side.
Offline
OK so this is how I have my service declared
t:=restServer.ServiceRegister(TPerfilService,[TypeInfo(IPerfilService)],sicShared);
t.ResultAsJsonObjectWithoutResult:=true;
t.SetWholeOptions([optResultAsJsonObjectWithoutResult]);
And the result did change from and JsonArray to a JsonObject but the result didnt get removed. I have tried moving other options around and changing the return type of the service but nothing worked. What am I doing wrong?
Offline
I tested your code. Without either one of these: t.ResultAsJsonObjectWithoutResult:=true; OR t.SetWholeOptions([optResultAsJsonObjectWithoutResult]); the JSON result is returned in the format below (with a JSON array).
{
"result": [
{
"remoteip": "",
"useragent": "bruno-runtime/2.2.0",
"header": "",
"servergreeting": "Welcome! Server online"
}
]
}
When you choose either one of those settings for ResultAsJsonObjectWithoutResult, the result is returned in the format below (without the JSON array)
{
"Result": {
"remoteip": "",
"useragent": "bruno-runtime/2.2.0",
"header": "",
"servergreeting": "Welcome! Server online"
}
}
The result text is still there, but now we have a JSON object instead of a JSON array. I guess this is what you want removed.
Last edited by JD (Today 10:24:04)
Offline
How did you define your IPerfilService method?
I guess something like
type
TMyResult = packed record
remoteip, useragent, header, servergreeting: RawUtf8;
end;
IIPerfilService = interface (IInvokable)
function DoSomeThing: TMyResult;
end;
The "Result" comes from the fact that it is a function, and the function RESULT is serialized as "Result".
Try to write it as:
IIPerfilService = interface (IInvokable)
procedure DoSomeThing(out remoteip, useragent, header, servergreeting: RawUtf8);
end;
Read again the documentation about how the methods are mapped to REST / JSON.
Offline
@ab I used my own example function just to get an idea of what Gabian04 wanted to achieve.
However, I can confirm that when the function is changed to a procedure, it works and this is the result
{
"remoteip": "",
"useragent": "bruno-runtime/2.2.0",
"header": "",
"servergreeting": "Welcome! Server online"
}
So I guess the problem is solved.
Last edited by JD (Today 21:09:07)
Offline