Migrating Serialization Changes Within an AIR Application

September 11th, 2008 by

I just submitted my entry to the AIR Cookbook for the AIR Cookbook Cook-off.

It solves the problem of having your AIR application store an IExternalizable class on disk but then later adding more fields to that class. How would you read the old version of the class without encountering a runtime error if you tried to read the new field that wasn’t present in the older serialization?

Go check it out the cookbook entry to find out how to do this and please rate the article!

Serialization Error/Bug When Using a ByteArray and readObject in an IExternalizable Class?

August 27th, 2008 by

I’ve encountered some odd behavior that I would have expected to work when calling readObject() to de-serialize an array of anonymous objects. If anyone knows what’s going on here, please enlighten me. I’ve also filed a bug on Adobe’s bug tracking system if anyone wants to follow the progress at Adobe’s end.

I’m trying to read all of the bytes in the readExternal() function of a class implementing IExternalizable, so that I may use the position property to move back in stream in case I need to do so. The problem only seems to occur if I am trying to de-serialize an Array of anonymous objects. If I put plain old Strings in the Array it will work fine. I find this odd since I would expect

public function readExternal(input:IDataInput):void {
  var arr:Array = input.readObject() as Array;
}

to have the exact same behavior as:

public function readExternal(input:IDataInput):void {
  var ba:ByteArray = new ByteArray(); 
  var inputBytes:uint = input.bytesAvailable;
  input.readBytes(ba);
  var baBytes:uint = ba.bytesAvailable;
  var arr:Array = ba.readObject() as Array;
  trace("inputBytes == baBytes ?= " + (inputBytes == baBytes)); // traces "inputBytes == baBytes ?= true
}

AIR installer and code attached below… Read the rest of this entry »