Remoting SDK + HTTPAPi :- Passing json object containing child class fields

Hi ,

I am using ROSDK + HTTPAPI to create a REST API based on existing server.
I have created a class inherited from TROComplexType as :

  stParent = class(TROComplexType)
    fName: ROUTF8String;
    FMiddleName: ROUTF8String;
    {$IFDEF RO_RTTI_Support} [ROSerializeAsUTF8String] {$ENDIF}
    property Name: ROUTF8String read fName write fName;
    {$IFDEF RO_RTTI_Support} [ROSerializeAsUTF8String] {$ENDIF}
    property MName: ROUTF8String read FLastName write FLastName;

based on above class, I have created two more classes as :

stChild1 = class(stParent)
      LastName: string;
      property LName: string read LastName write LastName;

    stChild2 = class(stParent)
          FSName: string;
          property SName: string read FSName write FSName;

Now I have created a service method as follows :

      function GetDemo(obj: stParent): string;

according to my requirements, JSON data from client can contain any value. for example it could be like :

		"LName": "Jain"


		"SName": "Jain"

I do not want to create two service methods having different parameter type.
Could anyone please suggest that how this can be achieved having parameter type as parent in service method and json input having child class fields.


you can include __type tag with actual class like

           "__type":"TPerson",  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Hi @EvgenyK

Sorry , but I could not get this , the example from MegaDemo does not have any child class inherited from TPerson.
The issue which I have mentioned is related with having child classes inherited from TPerson class and creating one service method to pass JSON for both parent and child class

In your case, you should add "__type":"stChild1" or "__type":"stChild2"

Create usual RO SDK client, set TROJsonMessage.IncludeTypeName to True and pass your childs to

function GetDemo(obj: stParent): string;

it will work as expected.

Hi @EvgenyK
Thank you for your quick response.
I tried implementing this , but not working for me. I have created a sample -

I am passing this sample JSON
“obj”: {
This has 2 issues :

  1. RTTI was not able to create stChild class as a workaround I followed StackOverflow link (

  2. After solving first problem , I was able to progress but could not get child class fields value from stParent object. I want to access all the fields passed from JSON.

Please let me know If missing anything

everything works as expected.
I’ve modified a bit your service method to be sure what object is used:

function TNewService.GetDemo(obj: stParent): string;
  if obj is stChild then
    Result := stChild(obj).LastName
    Result := obj.FirstName;
>curl -verbose -X POST "http://localhost:8099/api/parent" -H  "accept: application/json" -H  "content-type: application/json" -d "{\"obj\": {\"__type\":\"stChild\",\"FirstName\":\"Deepak\",\"LastName\":\"Jain\"}}"
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying
* Connected to localhost ( port 8099 (#0)
> POST /api/parent HTTP/1.1
> Host: localhost:8099
> User-Agent: curl/7.56.0
> Referer: rbose
> accept: application/json
> content-type: application/json
> Content-Length: 68
* upload completely sent off: 68 out of 68 bytes
< HTTP/1.1 200 OK
< Connection: close
< Content-Type: application/json; charset=utf-8
< Content-Length: 6
< Date: Thu, 19 Dec 2019 09:27:56 GMT
< Accept-Encoding: gzip, identity
"Jain"* Closing connection 0

as you can see, LastName was returned

Thanks @EvgenyK This is working now.

Hi @EvgenyK
The above solution is working as expected but now I have added interger and boolean type properties in parent class as follows :

  stParent = class(TROComplexType)
      FID: Integer;
      FFirstName: string;
      FBoolValue: Boolean;
      property FirstName: string read FFirstName write FFirstName;
      property ID: Integer read FID write FID;
      property BoolValue: Boolean read FBoolValue write FBoolValue;

Request body json is as :


I have debug code and found that exception is generated inside TROJSONSerializer.ReadInteger procedure as lItem is nil

procedure TROJSONSerializer.ReadInteger(const aName: string;
  anOrdType: TOrdType; var Ref; ArrayElementId: integer);
  lItem: TROJSONValue;
  lItem := IntReadObject(aName);
  if lItem = nil then raise EROJSONSerializerException.Create(err_FieldNotFound);
  case anOrdType of
    otUByte : byte(Ref) := StrToInt(lItem.AsString);
    otUWord : word(Ref) := StrToInt(lItem.AsString);
    otULong : integer(Ref) := StrToInt(lItem.AsString);

Same thing happening for boolean values.
This only works for string type properties.
I have update code on git repository with this sample

Could you please suggest me what am I missing here ?


it works as expected.
Can you specify what version of Remoting SDK you are using, pls?
it can be found in ...\RemObjects SDK for Delphi\Source\

this change that allows to read missing fields in HTTPApi requests, was made a year ago …

HI ,



Can you retest this issue with the RO v9.6+ ?