Question
· Feb 8

Deserialize class from JSon with nodes null

Hi all,

We have a class response inherited from %JSON.Adaptor with the following properties, also dependent classes:

 
Kurro.app.Msg.Search.Response
 
Kurro.app.Msg.Common.SearchCriteria
 
Kurro.app.Msg.Common.Availability
 
Kurro.app.Msg.Common.Acts
 
Kurro.app.Msg.Common.Parameters

Note: I've not written all nodes.

When we call to the API of the provider, we receive the following JSon

 
JSon response from provider

And we use the following command to deserialize the response

set tHttpResponse = ##class(%Net.HttpResponse).%New()
set tSC = ..Adapter.SendFormDataArray(.tHttpResponse,verbo,tHttpRequest,,,tUrl)
set content = ""
while (tHttpResponse.Data.AtEnd = 0) { 
   set content = content_tHttpResponse.Data.Read() 
}
do pResponse.%JSONImport(content)

As you can see, the provider has returned a null value in the availability.acts.actParameters node, instead of an array of data, and the deserialize of the JSon raises an error.

How we have to define our class to prevent that type of error? I mean, if the response is a null value, ignore this error and continue with the rest of the content.

Thanks in advance.

Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1.3 (Build 389U) Wed Feb 15 2023 14:50:06 EST
Discussion (3)2
Log in or sign up to continue