#1 Yesterday 18:52:41

Gabian04
Member
Registered: Yesterday
Posts: 2

I have a problem getting my Json without the Result:

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

#2 Yesterday 20:06:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,005
Website

Re: I have a problem getting my Json without the Result:

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". wink
And try to debug a little bit more on your side.

Offline

#3 Yesterday 20:16:05

Gabian04
Member
Registered: Yesterday
Posts: 2

Re: I have a problem getting my Json without the Result:

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

#4 Today 10:21:37

JD
Member
Registered: 2015-08-20
Posts: 126

Re: I have a problem getting my Json without the Result:

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

#5 Today 15:13:36

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,005
Website

Re: I have a problem getting my Json without the Result:

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

#6 Today 20:59:40

JD
Member
Registered: 2015-08-20
Posts: 126

Re: I have a problem getting my Json without the Result:

@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

Board footer

Powered by FluxBB