Flex – XML Serialization and De-Serialization of nested Object structures

actionscript-3apache-flexxml-serialization

Our Flex app would like to work with requests and responses as object graphs (nothing unusual there) e.g. response becomes the model of some view, and would be a structure with several layers of nesting.

** Now, ideally we would like to use the same client (and server) side objects for different message formats e.g. XML and AMF, and have a pluggable serialization/de-serialization layer (!)

AMF has serialization and matching of client to server using
[RemoteClass(alias="samples.contact.Contact")]
but it seems there is no equivalent for XML.

I am (somewhat optimistically) looking for a neat way of serializing the object graph to XML, to send through a HTTPService from the client.

For responses, the default 'object' and 'E4X' provide some de-serialization. This is handy, but of course we don't have the niceties of unpacking the XML back into specific AS classes like we do with AMF.

Any suggestions?
(did have one idea come through about wrapping/casting object as XML or XMLList – this does not seem to work, however)

Update:

Both these libraries look useful, and I will very likely use them at some point.

For now, I really need the simplicity of re-using the metadata set for the AMF3 serialization which we are using in any case ([RemoteClass],[Transient])

.. so the best option at the moment is AMFX – used Flex Data Services for AMF transfer using XML – classes in mx.messaging.channels.amfx package – only drawback at the moment is any Externalizable class is transformed into a Hex byte stream – and ArrayCollection is Externalizable! (hoping to workaround by serializing the internal Array in a subclass ..)

Hope that's useful to someone ..

Best Answer

Regarding the Xml serialization I can give you a starting point (as biased as it may be, though :D).

I am working on a project that allows for automatic conversion of AS3 objects to and from xml. It basically uses annotations on the model objects you use for communication in order to construct the xml structure or populating an object from xml.

It is called FlexXB and you can check it out at http://code.google.com/p/flexxb/. I started this project cos I got into the same issues at work (namely I have a server that communicates through xml) and I hoped it be of use to someone else.

Cheers,

Alex

Related Topic