Question
· Jun 16, 2023

JSON Import a List of Integers to Custom Message Class

I am working with a REST API JSON Response that contains a list of integers (departmentids).

JSON Response:

{
"status":"ACTIVE",
"departmentids":[
72
],
"subscriptions":[
{
"eventname":"LabResultAdd"
},
{
"eventname":"LabResultUpdate"
},
{
"eventname":"LabResultClose"
}
]
}

 

I am having trouble getting that to parse into my custom message structure using the %JSONImport method.

do pResponse.%JSONImport(tHttpResponse.Data.Read())

Here is my custom message class (pResponse):

Class AH.AHLIB.Custom.Athena.Message.GetEventsSubscribedResponse Extends (Ens.Response, %JSON.Adaptor)
{

Property status As %String;
Property departmentids As list Of %Integer;
Property subscriptions As list Of AH.AHLIB.Custom.Athena.Message.GetEventsSubscribedResponse.subscriptions;
Storage Default
{
<Data name="GetEventsSubscribedResponseDefaultData">
<Subscript>"GetEventsSubscribedResponse"</Subscript>
<Value name="1">
<Value>status</Value>
</Value>
<Value name="2">
<Value>departmentids</Value>
</Value>
<Value name="3">
<Value>subscriptions</Value>
</Value>
</Data>
<DefaultData>GetEventsSubscribedResponseDefaultData</DefaultData>
<Type>%Storage.Persistent</Type>
}

}

This is how the response parses in the message viewer trace:

How should I be defining the departmentids property in order to display in the XML Viewer? 

Discussion (1)1
Log in or sign up to continue

I found this is just an issue with the UI - I may try extending the XML Adaptor on my message class to see if that will help display the field. But I am able to access my field and was able to test it was available with the following in studio console:

set msg=##class(AH.AHLIB.Custom.Athena.Message.GetEventsSubscribedResponse).%OpenId(<messageIDfromtester>)

set test=""

set tsC=msg.%JSONExportToString(.test)

w test