Alternative for %ZEN.Auxiliary.altJSONProvider).%ConvertJSONToObject

Hello,

I want to convert a json, which passed on in the a REST call, into a request message. 

I use method %ConvertJSONToObject of the %ZEN.Auxiliary.altJSONProvider class.

Set sc = ##class(%ZEN.Auxiliary.altJSONProvider).%ConvertJSONToObject(%request.Content, "TestRequest", .request)

Is there an alternative for this? I want to avoid to use the %ZEN library.

Best Regards

Roger de Coninck

  • 0
  • 0
  • 113
  • 7
  • 1

Answers

If you work on versions 2016.1 and later you can use native JSON.

I want to de-serialize an json string, received via REST, into a Ens.Request.

Best Regards

Roger.

You need first to convert JSON into dynamic object and then create Ens.Request from that. Well, probably a subclass of Ens.Request as it can't hold any data.

I known how to create a dynamic object from a json string.

What do you mean with "create Ens.Request from that" ?

First create the request and assign the property one by one?

Or do you mean something else?

Best Regards

Roger.

First create the request and assign the property one by one?

Yes.

Comments

Hello, you can use the class, for serialize and deserialize JSON.

http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GJSON_refapi#GJSON_refapi_from-json

%DynamicObject.