Passing objects from Flex to Coldfusion

I couldn’t find anything online about how Coldfusion marshals a generic Flex object as an argument to a CFC method. So I decided to do a test. I created a generic object in Flex and then passed it through a remote call to coldfusion. Here is the actionscript for the object.

var genericObj:Object = new Object();
genericObj.testString1 = "hello";
genericObj.testString2 = "world";
genericObj.testNumber = 12.23;
genericObj.testArray = [1,2,3,4,5];
genericObj.testArrayCollection = new ArrayCollection(["testing","array","collection"]);

After breaking in the Coldfusion method call I took a look at the “Arguments” section my debugger:

Flex To CF Obj Marshal

Notice Coldfusion didn’t treat the Flex object as 1 argument. It took all of the sub objects and treated those as individual parameters.

Here are some options for getting the coldfusion arguments to work:
1. Use Coldfusion’s argument collection and don’t declare any arguments in the method.
2. Declare all of our objects parameters as arguments in Coldfusion. This way we have some documentation on what is being passed in, but a client side change could break things more easily than method 1.
3. Wrap the generic object in another object. Name the wrapped object the same as the argument name on the Coldfusion side. This will marshal the object as a struct.

I ended up using method 3. It provides the most flexibility while still preserving the fact that I am passing in an object into the method.

One Response to “Passing objects from Flex to Coldfusion”

  1. Receiving Flex Objects in Coldfusion, coldfusion component argument types | The Dev Pages Says:

    [...] http://www.joelconnett.com/flexobjectstocoldfusion.html [...]

Leave a Reply