Unable to completely deserialize a complex type result in a REST Advanced SmartObject

  • 15 February 2022
  • 0 replies
  • 206 views

Userlevel 5
Badge +20
 

Unable to completely deserialize a complex type result in a REST Advanced SmartObject

kbt154682

PRODUCT
K2 Cloud
K2 Five
BASED ON
K2 Cloud (all)
This article was created in response to a support issue logged with K2. The content may include typographical errors and may be revised at any time without notice. This article is not considered official documentation for K2 software and is provided "as is" with no warranties.

Issue

You are currently chaining together many REST service object methods on an Advanced SmartObject. Your goal is to have the serialize and deserialize methods work together so that users/developers do not need to call many SmartObjects to get readable results instead of string arrays. Currently, after running the deserialize methods on the relevant SmartObjects tied to your REST objects, you will still get a serialized list as your result. It will show up in a column on the results named "Serialized Item (String)."

Image

Symptoms

For the purpose of simplifying the symptoms, let's break down what your advanced SmartObject would be doing on the individual calls. Most likely the methods would look like this:

Image

 

 

Let's say our result set looks like this after querying from the REST Service. Notice how we have multiple complex types in play:

{"$type":"Company.k2RESTidentifier_Result2, Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","Table":{"$type":"Company.k2RESTidentifier_Table[], Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","$values":[{"$type":"Company.k2RESTidentifier_Table, Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","abalph":" Smith, John","aban8":"6666"},{"$type":"Company.k2RESTidentifier_Table, Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","abalph":"Joe Smith ","aban8":"6667"},{"$type":"Company.k2RESTidentifier_Table, Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","abalph":"Sam Smith","aban8":"1212"},{"$type":"Company.k2RESTidentifier_Table, Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","abalph":"Test Company","aban8":"5007"}]}}
 




Here we can see the first result is an object named Result2 which contains an array of type Table[]. This array Table[] contains many other objects of type Table. To get to our completely serialized ("Human Readable") data we need to deserialize against the relevant object types to break this result set down. So first we run the Deserialize method against the Result2 object. And in return we get the data below:

 

 

 

 

 

 

{"$type":"Company.k2RESTidentifier_Table[], Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","$values":[{"$type":"Company.k2RESTidentifier_Table, Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","abalph":" Smith, John","aban8":"6666"},{"$type":"Company.k2RESTidentifier_Table, Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","abalph":"Joe Smith ","aban8":"6667"},{"$type":"Company.k2RESTidentifier_Table, Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","abalph":"Sam Smith","aban8":"1212"},{"$type":"Company.k2RESTidentifier_Table, Company, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","abalph":"Test Company","aban8":"5007"}]}

 

 

 

Next, to finally get to our actual serialized data we run the "Deserialize Array" method on the above data for the Table SmartObject. However, this still returns a result set of 4 objects of type Table as seen in the above screenshot.

 

 

Troubleshooting Steps

Due to the result containing many complex types that are related, we need to deserialize the data set taking into consideration that we have an array of typed values. If our result set looks like the above then we need to be sure we are using the method "Deserialize Typed Array" instead of "Deserialize Array". The Deserialized Typed Array method will provide the complete results in human readable format. Technically we are passing it an Array of many types, even if that type is the single object version of Table. 

 

Once you run the "Deserialize Typed Array" method you would then get the results that look like this:

Image


0 replies

Be the first to reply!

Reply