Hide a property before pass the object to SalJSONSerializeUDV

Discussion forum about all things Gupta, OpenText and the community.
SSRJMC
Saudi Arabia
Posts: 30
Joined: 08 May 2017, 12:27
Location: Jeddah,Saudi Arabia

Hide a property before pass the object to SalJSONSerializeUDV

Post by SSRJMC » 30 Dec 2020, 07:56

Dear All,

How can I hide a property before pass the object to SalJSONSerializeUDV

Example:

Code: Select all

class Customer
{
   int CustId
   string FirstName 
   string LastName
   int age
}
I need a JSON File like Below (in the second array want to hide age properity)

Code: Select all

{
  "Customer": [
    {
      "CustId": 101,
      "FirstName": "John",
      "LastName": "Murphy",
      "age": 25
    },
    {
      "CustId": 102,
      "FirstName": "Sara",
      "LastName": "connie"
    }
  ]
}
Best Regards,
Abdul Rahman.S

a_sivababu
India
Posts: 498
Joined: 10 Mar 2017, 08:46
Location: Chennai,India

Re: Hide a property before pass the object to SalJSONSerializeUDV

Post by a_sivababu » 05 Jan 2021, 03:02

Hi Abdul,
I think you need to read JSON Serialize function in detail.

SalJSONSerializeUDV - This will send the JSON object to target application by using HTTP verbs
SalJSONDecserializeUDV - This will return the JSON string from target system and then you can assign back to JSON object variable. you can also use this function if there is a return value from the SalJSONSerializeUDV. this will accept target URL and also JSON string.

AFAIK, there is no option to hide the instance variable inside the object but you can send empty value if you do not want to send it.

To send header data and Query string, there is a new function and we already discussed in this forum. you can have a look at it,
SalJSONSerializeUDVEx
SalJSONDecserializeUDVEx

I have used this functions between TDMobile and TD .NET Web Services and also used for 3rd party application like easybill with headers and string.

Hope you are comfortable of using REST API. if not, try to use it with Postman to get more ideas as this tool can also be used for learning purpose for web services

Thanks
Sivababu A

SSRJMC
Saudi Arabia
Posts: 30
Joined: 08 May 2017, 12:27
Location: Jeddah,Saudi Arabia

Re: Hide a property before pass the object to SalJSONSerializeUDV

Post by SSRJMC » 05 Jan 2021, 07:51

a_sivababu wrote:
05 Jan 2021, 03:02
Hi Abdul,
I think you need to read JSON Serialize function in detail.

SalJSONSerializeUDV - This will send the JSON object to target application by using HTTP verbs
SalJSONDecserializeUDV - This will return the JSON string from target system and then you can assign back to JSON object variable. you can also use this function if there is a return value from the SalJSONSerializeUDV. this will accept target URL and also JSON string.

AFAIK, there is no option to hide the instance variable inside the object but you can send empty value if you do not want to send it.

To send header data and Query string, there is a new function and we already discussed in this forum. you can have a look at it,
SalJSONSerializeUDVEx
SalJSONDecserializeUDVEx

I have used this functions between TDMobile and TD .NET Web Services and also used for 3rd party application like easybill with headers and string.

Hope you are comfortable of using REST API. if not, try to use it with Postman to get more ideas as this tool can also be used for learning purpose for web services

Thanks
Sivababu A
Hi Mr.Sivababu

I am aware about (2 New function SalJSONSerializeUDVEx and SalJSONDecserializeUDVEx) in TD 7.2, I am working in hospital we are using TD 7.0 .
as you mention above the only way to handle header i must have to switch my development version to TD 7.2...

I tested my data in Postman tool and this Sample
https://wiki.tdcommunity.net/index.php/ ... ft_XMLHTTP
it's working fine no issue, but the sample defined send json data as a string but i want to send json data as a object.because REST API using HTTP_POST
the data will be differ each on every patient

do you have any solution how to send data as a object using with Microsoft_XMLHTTP
You do not have the required permissions to view the files attached to this post.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3145
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Hide a property before pass the object to SalJSONSerializeUDV

Post by Dave Rabelink » 05 Jan 2021, 09:22

Hi Abdul,

I'm not sure what you are asking. Maybe it is semantics.

In the end, you send a range of bytes, mostly represented as text, to a REST service.
Sending "objects" does not make sense. You "serialize" an object to data in a predefined format and then this data is send to the service.

The data itself, as defined in the format, can represent objects. But the data as a whole is just a range of bytes.

So we have TD objects (UDV's) which must be serialized to a predefined format (data) and then this data must be send to the REST service.
(in your case the data must be formatted as JSON).

To get the needed formatted data from your UDV, you can do this manually where you construct a JSON compatible string containing your data.
Al the UDV's combined will be your JSON body which can be send to the REST service.

You can use the SalJSONSerializeUDV function to do this for you. This function supports both serialize feature AND the send feature.
When you want to use a different way of sending (eg using MSXML library) you can leave the second parameter empty:
sURL String.
A URL to send the serialized data to. If empty, the UDV will be serialized to JSON only, and set to sResult parameter.

If you need to create JSON formatted data from an array of objects, you need to create a class having an array of UDV's.
That will serialize to JSON object having an array of objects.

As for the "Age" in your data.

If you assign NUMBER_Null to AGE, it will be serialized as NULL in the JSON data.

As far as I know, there is no way in TD to leave out the AGE when it is NULL.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests