I have created a Restful API with the post method.

the request of API should be like below

{

"data":"[      

{

   "name":"santhu",

   "age":"23",

   "country":"usa"

  },

  {

  "name":"sanju",

  "age":"22",

   "country":"India",

  "motherName":"mamas",

  "fatherName":"sivsa"

   }

]"

}

Array contains list of objects.The number of fields for each object will be vary .first object contains 3 fields 2nd object contains 5 field,I want to deserialize the above "data"  kindly help me to get rid of this.

thanks in advance

Regards 

Santhu

Hi Santhosh,

You will need to have all the attributes there.

The object that has fewer fields will return the others empty.

There is no problem, the fields which aren't send will be just empty. Just be sure to add all the fields on the struct. You can use the shortcut from OutSystems to create the struct.


santhu MS wrote:

I have created a Restful API with the post method.

the request of API should be like below

{

"data":"[      

{

   "name":"santhu",

   "age":"23",

   "country":"usa"

  },

  {

  "name":"sanju",

  "age":"22",

   "country":"India",

  "motherName":"mamas",

  "fatherName":"sivsa"

   }

]"

}

Array contains list of objects.The number of fields for each object will be vary .first object contains 3 fields 2nd object contains 5 field,I want to deserialize the above "data"  kindly help me to get rid of this.

thanks in advance

Regards 

Santhosh MS



Thank you  for the quick response @Nuno Rolo and @Rossi


The problem here is, in each request, more attributes may add, we can't predict the structure of the request.


Regards

Santhu



Well in that case that will be more difficult.

OutSystems is a strong typified platform and for that reason, you need to know what is being sent.

Probably you will need to get the response as text and process it manually. But I would also advise you to better understand the use case, I doubt that you will need all those fields.

Hi Santhu,

Are you sure that the attribute will be keep on adding to the response and you don’t know all of them in advance to build a structure as a superset, my worry is how do you handle the response and identify which data is coming in which field?


Regards,

-PJ-