views:

217

answers:

1

I have been trying to test my application to make sure that all the important classes can serialize/reload themselves properly (especially those which implement IExternalizable):

[Test]
public function testMyObjectSerialization():void {
    var myobj:MyObject = new MyObject();
    var ba:ByteArray = new ByteArray();
    ba.writeObject(myobj);
    ba.position = 0;
    var loadedObj:MyObject = ba.readObject();
    assertMyObjectEqual(myobj, loadedObj);
}

And I would like to be warned when I try to serialize a strongly-typed object which does not have a [RemoteClass] set (because that almost certainly represents a bug in my code).

So, is there any way to configure the AMF serializer to give warnings?

Also, it seems like this might be possible using services-config.xml… But the documentation seems to imply that services-config is channel-level, and I'd really like it if my unit tests could run without talking to the server (and I'm not using LCDS, so a bunch of the services-config wouldn't apply to me anyway).

+2  A: 

There is no way to configure the native AMF serialization/deserialization from the Flash Player to give you warnings if [RemoteClass] or any other metadata is set or not.

However you can write your own class to do that - you can register all the objects in a list and check for [Remote] using flash.utils.describeType. Or use a wrapper over writeObject which check for the [Remote] metadata.

Cornel Creanga
Unfortunately, though, that won't work for classes which implement `IExternalizable`, because there's no way of knowing what they will write to the output stream. Of course, I could create a subclass of `ByteArray`, which watches *everything* being written to it… But that seems like a fair amount of pain :(
David Wolever
Also, do you have a reference for "there is no way to configure the native AMF serialization/deserialzation"? Because it *seems* like, if I was using `services-config.xml` and an LCDS server, then it would be possible…
David Wolever
I do not have a public reference, I just asked an FP engineer near my desk. On the server side it is a different story..you can customize many things and the code is open source.
Cornel Creanga
Ah, ok :) That's much better than I've got. Thanks.
David Wolever