JSON, "value" when function response is TList<myclasstype>

Hi Everybody,

I'm using TMS XData\Demos\Swagger, and I put a new service implementation

    [Route('users-get')]
    [HttpGet]     function GetUsers(group_id: TGUID ):TList<T_User>;

Reponse is:

{
  "value": [
    {
      "id": "string",
      "FirstName": "string",
      "LastName": "string"
    }
  ]
}

I there any other type instead if TList that will return the response like:

[
    {
      "id": "string",
      "FirstName": "string",
      "LastName": "string"
    }
]

Or any event that I can Parse the response text and send it correctly (as above)?

Also is there any way to use FirstName instead of FFirstName in class definitions?

  [Entity, Automapping]
  T_User = class
  strict private
    Fid: TGUID;
  public
    FFirstName                                : string; //should be FirstName but output trim 'F' in the front of var name;
    LastName                                 : string;
    property Id: TGUID read FId write FId;
  end;

Thanks,
Mihai

The added "value" is an XData convention. To return an arbitrary value, you must return a TStream object which you can add any value to it. For example:

uses {...}, Bcl.Json;
...
function TMyService.Data: TStream;
var
  Data: TArray<string>;
begin
  Result := TMemoryStream.Create;
  TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);

  SetLength(Data, 2);
  Data[0] := 'First';
  Data[1] := 'Second';
  TJson.SerializeAs<TArray<string>>(Data, Result);
end;

Wasn't it already answered here? change JSON property name - #2 by wlandgraf

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.