|
GeneralDescription
FlexXB - automated (de)serialization for Flex and Air applications
Featured IntroductionWe're all familiar with the power of AMF and how easy it makes the communication with the backend server. It is a binary protocol (thus very compact and fast), basically ActionScript bytecode that is natively interpreted into an AS3 object. The only "issue" would be the backend server that will have to know AMF (sure, there have been, for quite some time now, a variety of products that provide a seamless way for AMF serialization: BlazeDS, FluorineFX, just to name a few). What happens if one finds oneself in the company of an "XML spitting server" (like the situation I find myself in some of my work projects) for compatibility sake, with no way of making any common sens changes to it (like adding a communication layer smart enough to make the switch between XML and AMF serialization on demand - talk xml with legacy clients and AMF with the cool kids :D)? In that case one might be forced to implement a way to send and receive objects through XML. Fortunately, thanks to E4X the task is not quite as horrific as it might appear. Still, a multitude of issues appear with XML communication:
FlexXB appeared in my mind as an attempt to shed some light into all of these problems and, hopefully, more: a way to automate the serialization/deserialization process while keeping the model objects used in the communication free of ugly toXML() : XML and fromXML(xmlData : XML) : Object. The most simple way of marking the model objects for serialization seemed to be the use of annotations (to some extent similar to JAXB approach, that is, if I'm not terribly mistaking). I plan to include in this project what I've learned and continue to learn about talking XML with a backend server and hope that all this fuss will someday help someone who might find himself in the same position as I did. What is FlexXB?FlexXB is an ActionScript library designed to automate the AS3 objects' serialization to XML to be sent to a backend server and the xml deserialization into AS3 objects of a response received from that server. How does it work?In order for FlexXB to be able to automate the (de)serialization process, the model objects involved must be "decorated" with AS3 metadata tags that will instruct it on how they should be processed:
All this information is linked to the object by adding metadata tags (annotations - in Java - or attributes - in .NET) to the class definition of the object in question. When an object is passed to it for serialization, it inspects the object's definition and extracts a list of annotations describing the way an object of that type needs to be (de)serialized. It keeps the generated list in a cache in order to reuse it if need arises and then builds the corresponding XML using the information provided by the annotations. Any object field that does not have an annotation defined is ignored in the (de)serialization process of that object. There are six built-in annotations for describing object serialization, one being class-scoped, the other field-scoped:
| |
Hey, this wiki stuff is pretty darn cool!