Flex - XML ​​Serialization and De-serialization of Nested Object Structures

Our Flex application needs to work with requests and responses in the form of graphs of objects (nothing fancy there), for example. the answer becomes a model of some kind and will be a multi-layer nesting structure.

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

AMF has client-to-server serialization and mapping using [RemoteClass (alias = "samples.contact.Contact")] but there seems to be no equivalent for XML.

I was (somewhat optimistic) looking for a neat way to serialize an object graph to XML to send over HTTPService from the client.

For default answers, "object" and "E4X" provide some de-serialization. This is handy, but of course we don't have the ability to decompress the XML back into specific AS classes like in AMF.

Any suggestions? (is it really the idea that the wrapping / casting object is being used as XML or XMLList - this doesn't seem to work)

Update:

Both of these libraries look useful and I will probably use them at some point.

Currently I really need the ease of reusing the AMF3 serialization metadata set, which we use anyway ([RemoteClass], [Transient])

.. so the best option at the moment is AMFX - used Flex data services to pass AMF using XML classes in the mx.messaging.channels.amfx package - just a drawback at the moment - any Externalizable class turns into a hex byte stream - and ArrayCollection is the appearance! (hoping for a workaround, by serializing the internal array in the subclass ..)

Hope this is helpful to someone.

+1


source to share


4 answers


As far as Xml serialization goes, I can give you a starting point (kind of biased, though: D).

I am working on a project that allows to automatically convert AS3 objects to and from xml. It mainly uses annotations on model objects that you use to link to build an xml structure or populate an object from xml.

It's called FlexXB and you can check it out at http://code.google.com/p/flexxb/ . I started this project because I had the same problems at work (namely, I have a server that communicates via xml) and I was hoping it would be useful to someone else.



Greetings,

Alex

+5


source


Another project: FleXMLer ( http://code.google.com/p/flexmler/ ).
It has a direct relationship to asx3m, where you can just call:

new FleXMLer (). serialize (obj);


Or you can customize the names of the XML elements, skip elements, and customize the serialization order of arrays and hash tables. Thank you for entering.

+2


source


checkout asx3m project at http://code.google.com/p/asx3m This is an AS3 port of the Java XStream serialization library and works very well. I did this because I needed to connect to a server platform that used XStream to exchange data objects and put a lot of work into it. It can be extended to serialize AS3 objects in any format (like JSON) and can take advantage of the power of user-defined meta tags. Cheers,

Tomislav

+1


source


There is also a library including JSON available from Adobe. And since ActionScript is a superset of JavaScript ... and JSON increasingly supports cross-framework ...

0


source







All Articles