tags:

views:

80

answers:

1

As the title suggests, is it possible to use AMF to encode/decode Dictionaries (without subclassing, that is)?

For example, here's a test case:

function serializeAndReload(obj:*):* {
    var serialized:ByteArray = new ByteArray();
    serialized.writeObject(obj);
    serialized.position = 0;
    return serialized.readObject();
}

function test():void {
    var d:Dictionary = new Dictionary();
    d[{}] = 42;
    d[d] = true;
    var x:* = serializeAndReload(d); // <<< x is an instance of Object
    trace(x['[object Object]']); // <<< traces '42'
}
A: 

You may be over-thinking. I use Object instead of Dictionary and it is automatically encoded using AMF. I use pyamf all the time to pass Objects/dicts around and its always worked without any mental effort on my part. Never have I needed to manually serialize/deserialize anything

Jason Spitkoski
It's true that Objects work nicely - but the Dictionary class is different from Object. Objects can only have Strings as keys, while Dictionaries can have any object.
David Wolever