Question
· Oct 20, 2022

Not able to convert %Stream.TmpBinary; to JSON property

Hello,

I’m creating a REST API service but I need to convert my object in JSON.

Class message_B Extends Ens.Request 

Property ClientId As %String(MAXLEN = "");

Property mesagge As %Stream.TmpBinary;
}

set pRequest = ##Class(message_B).%New()
​do ##class(Ens.Util.JSON).ObjectToJSONStream(pRequest, .content)

it is ignoring message property in json dueto its data type %Stream.TmpBinary

Could you please help me to resolve it?

Product version: IRIS 2022.1
Discussion (2)1
Log in or sign up to continue

I do not use Ensemble, but I would try using the JSON-Adaptor, something like this

Class MessageB Extends (Ens.Request, %JSON.Adaptor)
{
   Property ClientId As %String(MAXLEN = "");
   Property message As %Stream.TmpBinary;
}

For example

s r=##class(MessageB).%New()
s r.ClientId=12345
d r.message.Write("part1")
d r.message.Write("part2")
w r.%JSONExportToStream(.s)
d s.Rewind()
w s.Read(s.Size) --> {"ClientId":"12345","message":"cGFydDFwYXJ0Mg=="}