0

I need to extend an ArrayCollection in Flex to implement something like this. But when I send it to the server, it appears that the serialization fails.

ArgumentError: Error #2004: One of the parameters is invalid.
    at ObjectOutput/writeObject()
    at mx.collections::ArrayList/writeExternal()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ArrayList.as:595]
    at mx.collections::ArrayCollection/writeExternal()[E:\dev\4.x\frameworks\projects\framework\src\mx\collections\ArrayCollection.as:159]
    at flash.net::NetConnection/invokeWithArgsArray()
    at flash.net::NetConnection/call()
    at mx.messaging.channels::NetConnectionChannel/internalSend()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:276]
    at mx.messaging.channels::AMFChannel/internalSend()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:364]
    at mx.messaging::Channel/send()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\Channel.as:1013]
    at mx.messaging.channels::PollingChannel/send()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:365]
    at mx.messaging::ChannelSet/send()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1424]
    at mx.messaging::MessageAgent/internalSend()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\MessageAgent.as:1263]
    at mx.messaging::Producer/internalSend()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\Producer.as:171]
    at mx.messaging::AbstractProducer/send()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\AbstractProducer.as:561]
    at mx.rpc::AsyncRequest/invoke()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:153]
    at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::invoke()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:379]
    at mx.rpc.remoting::Operation/http://www.adobe.com/2006/flex/mx/internal::invoke()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\remoting\Operation.as:287]
    at mx.rpc.remoting::Operation/send()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\remoting\Operation.as:254]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.rpc::AbstractService/http://www.adobe.com/2006/actionscript/flash/proxy::callProperty()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AbstractService.as:408]

Is there any way to work around this?

Details: Using Flex 4.1, with BlazeDS and Java

This is the extended class:

package 
{
    import mx.collections.ArrayCollection;

    public class NewEntryArrayCollection extends ArrayCollection
    {
        private var newEntry:Object;

        // callback to generate a new entry
        public var factoryFunction:Function;

        // callback to test if an entry is empty and should be deleted
        public var emptyTestFunction:Function;

        public function NewEntryArrayCollection(source:Array=null)
        {
            super(source);
        }

        override public function getItemAt(index:int, prefetch:int=0):Object
        {
            if (index < 0 || index >= length)
                throw new RangeError("invalid index", index);

            if (index < super.length)
                return super.getItemAt(index, prefetch);

            if (!newEntry)
                newEntry=factoryFunction();
            return newEntry;
        }

        override public function get length():int
        {
            return super.length + 1;
        }

        override public function itemUpdated(item:Object, property:Object=null, oldValue:Object=null, newValue:Object=null):void
        {
            super.itemUpdated(item, property, oldValue, newValue);
            if (item != newEntry)
            {
                if (emptyTestFunction != null)
                {
                    if (emptyTestFunction(item))
                    {
                        removeItemAt(getItemIndex(item));
                    }
                }
            }
            else
            {
                if (emptyTestFunction != null)
                {
                    if (!emptyTestFunction(item))
                    {
                        newEntry=null;
                        addItemAt(item, length - 1);
                    }
                }
            }
        }
    }
}
Akshay
  • 1,606
  • 3
  • 17
  • 32
  • 3
    You'll have to provide more info/code on your implementation, cause all that function does is serializing the 'source' property, which should be an Array. – RIAstar Apr 09 '12 at 15:29
  • 1
    Why not just send the Array to the server instead of the collection? – JeffryHouser Apr 09 '12 at 15:48
  • I think the problem is your local object now contains public fields that can't be serialized in the messaging ArrayCollection on the java side. As others suggested one option is to switch to using a custom class (say an extension of ArrayCollection on the server side duplicating what you've added in your client side extension). I think one option might be making it so the two new variables are private and are set through public methods (not a setter just a regular method) so as to "hide" the variables, I don't think extra public methods will cause an issue. – shaunhusain Apr 09 '12 at 16:34
  • I have added the subclass in the post. I guess I can just send the source Array to the server as suggested, but it would be interesting to find out what is causing this problem. Thanks! – Akshay Apr 10 '12 at 05:22
  • Could he use the [Transient] [metadata tag](http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf680e1-7ffe.html#WS2db454920e96a9e51e63e3d11c0bf69084-7a19) for those public properties that don't need to be serialized and sent to the server? Admittedly a bit of a newbie when it comes to remoting. – Sunil D. Apr 10 '12 at 07:27

0 Answers0