Is it currently (Delphi 12) possible to write in server method parameters some class and receive it from simple JSON?
Now I have:
type
TTestParam = class
fVal1: Integer;
end;
{$METHODINFO ON}
TTest = class(TDSServerModule)
strict private
public
function updateTest(param: TJsonObject): TTestParam;
end;
{$METHODINFO OFF}
implementation
function TTest.updateTest(param: TJsonObject): TTestParam;
var
lParam: TTestParam;
begin
lParam := TTestParam.Create;
try
TJson.JsonToObject(lParam, param);
Result := TTestParam.Create;
Result.fVal1 := lParam.fVal1 * 2;
finally
lParam.Free;
end;
end;
My expectation:
function TTest.updateTest(param: TTestParam
): TTestParam;
begin
Result := TTestParam.Create;
Result.fVal1 := Param.fVal1 * 2;
end;
BTW – for output I a little wrapper on WebDispacher event:
var
Aux: TJSONValue;
begin
//remove [] element
Aux := ResultVal;
ResultVal := TJSONArray(Aux).Items[0];
ResultVal.Owned := False;
//TJSONArray(Aux).Remove(0);
Aux.Free;
Aux := ResultVal;
ResultVal := TJSONObject(Aux).GetValue('fields');
ResultVal.Owned := False;
Aux.Free;
Handled := true;
end;
Can I do maybe some reverted for input?
6