Can a JSON variable (%Library.DynamicObject) ever be a property in an Ens.Request object? Nothing but <INVALID OREF> errors

I have a process that takes data from a CSV file (actually a record mapper object) and creates a nicely formatted JSON string I would love to send this along to a RESTful business operation.  However no matter what I try, I continually get <INVALID OREF> errors when trying to populate the object that extends Ens.Request to give it the JSON string.

I can add strings, other objects, you name it - but stuffing a JSON formatted variable/object into another object I want to send someplace is proving to be an impossibility.

Does anyone have an example of sending an Ens.Request or other object (not an HTTPRequest object - but some other custom object) containing a JSON string to an Operation where the operation ultimately pulls the JSON from the object that was sent to it, makes the REST POST call and sends the response back?

Many thanks in advance! For some reason, every example I see deals with building "services", and the operations used have examples that have everything BUT a JSON payload. Is there some magic words or special dance I am missing? ;-)

(I also included the Cache tag since just the simple act of creating a class that extends %Persistent, having a property that is %Library.DynamicObject or arrays or anything, cannot seem to accept a JSON formatted variable as a value without blowing OREF errors.)

 

 

 

  • 0
  • 1
  • 195
  • 7
  • 3

Answers

I had this exact issue last week, and this is how I got around it. For clarity, I wanted to pass the Dynamic Object from a process to an operation.

I created my dynamic object within the Process, and then used the %ToJSON Method to put the JSON within a GlobalBinaryStream (which can be passed through the request).

In the Operation, I then use the %FromJSON Method of DynamicAbstractObject to then have the Dynamic Object within the operation.

 

Hi Ryan,

Ens.Request class does not contain any properties. so you should make a sub class and put a %String property. 
Json is basically a string.

Example:

Class User.REQ.JsonRequest Extends Ens.Request

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

 

 

DynamicObject is not in memory thus can't be passed along as a request property

You have to convert to json string and convert it back when you get the request. That's the whole concept of it

If you need any help in implementation, let me know. You can email me directly 

Yep. this is exactly what I did. I added a property JSON that was a string, and also added one that was a %Library.DynamicObject. Both of them when I went to assign the JSON array as in:

Set MyObj.JSON=JSONString.%ToJSON()

gave me the INVALID OREF error.

I'm going to try what some others have mentioned - pipe that data from %ToJSON() into a stream property in an object that extends Ens.Request and give that a shot.

Thanks!

If you have team viewer,I can take a look at your code and resolve it.

Shouldn't that be:

Set MyObj.JSON={}.%FromJSON(JSONString)

For Set MyObj.JSON=JSONString.%ToJSON() to signal <INVALID OREF> then either local variable MyObj is not an oref or local variable JSONString is not an oref.  Make sure that JSONString is really a %DynamicObject by doing a WRITE JSONString before doing the Set command.  The WRITE statement should write some like 99@%Library.DynamicObject .