views:

5079

answers:

4

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 ..

A: 

There's a library including JSON available from Adobe, too. And since ActionScript is a superset of JavaScript ... and JSON is increasingly supported cross-framework ...

le dorfier
+2  A: 

Hi,

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

+1  A: 

Hi, checkout asx3m project at http://code.google.com/p/asx3m It's an AS3 port of Java XStream serialization library and works pretty well. I made it because I had to connect to a server platform that used XStream for exchanging data objects and put a lot of work in it. It can be extended to serialize AS3 objects to any format (JSON for example) and could leverage power of user defined metatags. Cheers,

Tomislav

Tomislav Pokrajcic
+1  A: 

Yet another project: FleXMLer (http://code.google.com/p/flexmler/).
It has both the straightforward attitude of asx3m where you can just call:

new FleXMLer().serialize(obj);

Or you can customize XML element names, skip elements and tweak the way arrays and hash tables are serialized. Would appreciate your input.