Search code examples
apache-flexamfiexternalizable

Flex: Unexpected leakage with RemoteObject + IExternalizable?


I've been tinkering with IExternalizable, but I've noticed some unexpected behavior. I've got this class:

public function readExternal(input:IDataInput):void {
    input.readObject();
    input.readObject();
    input.readObject();
}

public function writeExternal(output:IDataOutput):void {
    output.writeObject("first string");
    output.writeObject(424242);
    output.writeObject("second string");
}

But when I try to serialize this class using AMF and send it to a remote server (via RemoteObject), Charles shows me that the request looks like this:
unexpected result http://img.skitch.com/20100406-cjawastycagp1x2chbe76k2suu.png

But it seems wrong that my serialized object is leaking out into the rest of the request.

So, what am I doing wrong? Is there some part of the documentation I've missed?


Solution

  • You code seems fine, however you should serialize using the proper methods (writeUTF for strings, writeInt for int etc). Anyway Charles seems to not work properly with objects implementing IExternalizable (I'm using version 3.4.1), so you should not rely on what it is showing.

    Not directly related to your question - do you really need to use IExternalizable? You are going to lose some benefits related to AMF compression algorithm (unless you are not going to implement all this things in your writeExternal method).