views:

302

answers:

2

What is serialization support like for the new Vector class? I have a Vector.<GameMove> which I'd like to serialize into a ByteArray. GameMove is a custom class.

I presume it's necesssary to call registerClassAlias() on GameMove, but do I also have to register Vector.<GameMove>? It's it it's own distinctive type, or is it kinda composed of those two types?

A: 

The sender always has control over what class is used when serializing an object. For example, Fluorine will send anything that implements IList in .NET as an ArrayCollection to a Flex client or Array to a Flash client. In this case, there is no option except to use ArrayCollection or Array.

Other AMF implementations may vary. Fluorine processes registered class aliases last, but others might do it first. So whether Vector.<> will be serialized properly both ways depends on the server you're using.

The best way to know if it works with your server is to just test it. Then if it doesn't work, ask a more specific question to find out if there's a workaround or if it's considered a bug.

Sam
Thanks, Sam. Though I'm not actually serializing to a server, just into a ByteArray for persistence, so it's the internal "player" implementation of amf3 that matters to me.
aaaidan
A: 

As it turns out, no, the vector holding a custom type does not need to be registered as a "pair", in addition to the type that it contains.

In fact, Vector doesn't need to be registered at all, it seems - just the type it's holding. At least in my case of serializing to a ByteArray (AMF3, of course).


As an aside, however, I found a very odd issue where subclasses of Array cannot be deserialized. I'll post this in a seperate question.

aaaidan