Scriptico

Issue in serialization of subclasses of any IExternalizable implementation

Let’s consider the following use-case.

There is a client – server basic application. The client uses a simple remoting to communicate with the server side. The server side could be powered on WebORB, BlazeDS or any other solution. The client side is using the FLEX framework. That is it about the technology stack. Now, let’s forget about the server side and just have a look at the following client code

package com.blog.ri
{
	import mx.collections.ArrayCollection;

	public class MyCollection extends ArrayCollection
	{
		public function MyCollection(source:Array=null)
		{
			super(source);
		}
	}
}

Additionally, let’s assume we have the following class and it is mapped to a server side class:

package com.blog.ri
{
	[Bindable]
	[RemoteClass(alias="com.blog.ri.MyEntity")]
	public dynamic class MyEntity
	{
		private var _myCollection:MyCollection;

		public function get myCollection():MyCollection
		{
			if(_myCollection == null)
				_myCollection = new MyCollection();

			return _myCollection;
		}

		public function set myCollection(value:MyCollection):void
		{
			_myCollection = value;
		}
	}
}

Also, the server side service exposes to the clients the void save(MyEntity candidate) method and I invoked it on the client side as it shown below:

package com.blog.ri
{
	public class MyService
	{
		private var _remoteObject:RemoteObject;

		public function MyService()
		{
			var channelSet:ChannelSet = new ChannelSet();
			var amfChannel:AMFChannel = new AMFChannel("my-amf", "http://localhost/weborb.aspx");
			channelSet.addChannel(amfChannel);

			_remoteObject  = new RemoteObject("GenericDestination");
			_remoteObject.channelSet = channelSet;
			_remoteObject.source = "com.blog.ri.MyService";
			_remoteObject.getDetailedStatistic.addEventListener("result",onItemSaved);
			_remoteObject.addEventListener("fault", onFault);
		}

		public function save(candidate:MyEntity, responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = _remoteObject.save(candidate);

			if( responder != null )
				asyncToken.addResponder( responder );
		}

	}
}

Finally, I want to save a new instance of the MyEntity class in the main mxml file as shown below:

protected function creationCompleteHandler():void
			{
				var myService:MyService = new MyService();

				var candidate:MyEntity = new MyEntity();
				candidate.myCollection = new MyCollection();

				myService.save(candidate);
			}

That is it. When I run the code, I received the following exception:

ArgumentError: Error #2004: One of the parameters is invalid.
at flash.net::NetConnection/invokeWithArgsArray()
at flash.net::NetConnection/call()
at mx.messaging.channels::NetConnectionChannel/internalSend()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:281]
at mx.messaging.channels::AMFChannel/internalSend()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:364]
at mx.messaging::Channel/send()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\Channel.as:1002]
at mx.messaging.channels::PollingChannel/send()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:394]
at mx.messaging::ChannelSet/send()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1429]
at mx.messaging::ChannelSet/channelConnectHandler()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1084]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.messaging::Channel/connectSuccess()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\Channel.as:1148]
at mx.messaging.channels::AMFChannel/resultHandler()[E:\dev\hero_private\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:576]

As you can see, I extended the ArrayCollection class and according to the Adobe documentation, the ArrayCollection implements the IExternalizable interface. I decided to localize the problem and created a simple class that implements IExternalizable. Then, I extended this class in some other MyChild class and defined the MyChild property in the MyEntity class. In this case, I received the exception above as well. Is the problem in how I wrote the code or is it a bug in Flex?

Resources

Category: Action Script, Flex

Tagged:

Leave a Reply

ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.