My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
Usage  
FlexXB usage
Featured
Updated Jan 7, 2011 by alex.id....@gmail.com

Using the FlexXB library

To serialize an object to xml:

com.googlecode.serializer.flexxb.FlexXBEngine.serialize(object)

To deserialize a received xml to an object, given the object's class:

com.googlecode.serializer.flexxb.FlexXBEngine.deserialize(xml, class)

To register a custom annotation, subclass of com.googlecode.serializer.flexxb.Annotation:

com.googlecode.serializer.flexxb.FlexXBEngine.registerAnnotation(name, annotationClass, serializerClass, overrideExisting)

To register a converter that will handle how an object of a specific type is converted to a String value that will be attached to the xml representation and viceversa:

com.googlecode.serializer.flexxb.FlexXBEngine.registerSimpleTypeConverter(converterInstance, overrideExisting)

To enable/diable object caching:

//disable
com.googlecode.serializer.flexxb.FlexXBEngine.configuration.cacheProvider = null;
//enable
com.googlecode.serializer.flexxb.FlexXBEngine.configuration.cacheProvider = new com.googlecode.flexxb.cache.ObjectCache();
   //or
com.googlecode.serializer.flexxb.FlexXBEngine.configuration.cacheProvider = new com.googlecode.flexxb.cache.ObjectPool();

In order to register a class descriptor created via the FlexXB API for classes that cannot be accessed in order to add annotations: com.googlecode.serializer.flexxb.FlexXBEngine.instance.api.processTypeDescriptor(apiTypeDescriptor)

To provide an API descriptor file content in which the class descriptors are depicted in an XML format:

com.googlecode.serializer.flexxb.FlexXBEngine.instance.api.processDescriptorsFromXml(xml)

Note: Make sure you add the following switches to your compiler settings: -keep-as3-metadata XmlClass -keep-as3-metadata XmlAttribute -keep-as3-metadata XmlElement -keep-as3-metadata XmlArray -keep-as3-metadata ConstructorArg

Annotating model classes

There are four annotations defined:

XmlClass [XmlClass(alias="MyClass", useNamespaceFrom="elementFieldName", idField="idFieldName", prefix="my", uri="http://www.your.site.com/schema/", defaultValueField="fieldName", ordered="true|false", version="versionValue")]
XmlAttribute [XmlAttribute(alias="attribute", ignoreOn="serialize|deserialize", order="orderIndex", version="versionValue")]
XmlElement [XmlElement(alias="element", getFromCache="true|false", ignoreOn="serialize|deserialize", serializePartialElement="true|false", order="orderIndex", version="versionValue")]
XmlArray [XmlArray(alias="element", memberName="NameOfArrayElement", getFromCache="true|false", type="my.full.type" ignoreOn="serialize|deserialize", serializePartialElement="true|false", order="orderIndex", version="versionValue")]

Note: Using as alias "*" on a field will force the serializer to serialize that field using an alias computed at runtime by the runtime type of the field's value, except for XmlArray. For XmlArray using the "*" alias will cause the members of the array value to be rendered as children of the owner object xml rather than children of an xml element specifying the array.

Comment by zakmccra...@web.de, Oct 9, 2010

Am i right that it's currently not possible to deserialize array structures that contain multiple types? It seems to work only with a single type when specifiying it in the annotation, or when serializing first and then deserializing (as if it would cache the alias <> type association).

Comment by project member alex.id....@gmail.com, Oct 10, 2010

Well, you should be able to process arrays with different item types by not setting the memberType field in the XMLArray annotation. Then the engine will attempt to determine the element type by inspecting the tag name or the namespace of that element. Now in order for this to work you would need to make sure all required types are already registered with the engine (you can use processTypes method in the engine to force registration of specific types).

Comment by zakmccra...@web.de, Oct 10, 2010

Ah silly me, i've spent hours fiddeling with custom built type-descriptors while the solution is so simple, processTypes did the trick, thanks :)

Comment by basakaru...@gmail.com, Dec 22, 2010

Need to deserialize a xml with the following structure: <Addresses>

<Add>
<City>abc</City> <Pin>123</Pin>
</Add> <Add>
<City>def</City> <Pin>345</Pin>
</Add>
</Addresses> I am using the annotation as: [XmlArray(alias="Addresses", memberName="Add", type="vo.Address")] public var addresses : ArrayCollection?; But it returns me a runtime null exception. Any idea?

Comment by project member alex.id....@gmail.com, Dec 22, 2010

It seems to be a common problem with arrays. Did you make sure your Address class is referenced somewhere in the project? Take a look on the FAQ page for solutions: http://code.google.com/p/flexxb/wiki/FAQ.

If this does not solve your problem please post a discussion on the group so we may see this further.

Comment by basakaru...@gmail.com, Dec 23, 2010

Thanks for the comment. It solved the problem like magic. We need to create a dummy instance of the "Address" class, so that it is referenced. An excellent serializer/deserializer that can be used for serialization/deserialization routine.

Comment by basakaru...@gmail.com, Dec 28, 2010

Hi, How to assign/deserialize object having multiple namespaces in a single node, for eg.

<SampleNode? xmlns:a="http://www.abc.com" xmlns:b="http://www.def.com">

Thanks

Comment by project member alex.id....@gmail.com, Dec 28, 2010

You have to define the namespace references as annotations on the class. For example:

[Namespace(prefix="xsi", uri="http://www.w3.org/2001/XMLSchema-instance")]
[XmlClass(name="node", uri="htp://www.w3.org/xml")] public class Node {
[XmlAttribute(namespace="xsi")] public var type : String = "xml";
public function Node() { }
}

Here the class has its own uri but an element of it will be set in a different namespace. You define as many namespaces as you need with the Namespace annotation at the top and then reference them in the field annotations like in the above example.

Comment by basakaru...@gmail.com, Mar 3, 2011

Hi, I need to add namespace to an "XmlArray?" root element containing another class as the child element. The structure should look like : <RootNode? xmlns:a="http://www.google.com">

<ChildNode><Id>1</Id><Name>abc</Name></ChildNode> <ChildNode><Id>2</Id><Name>def</Name></ChildNode>
</RootNode> Unfortunately, it is now appearing as : <RootNode>
<ChildNode? xmlns:a="http://www.google.com"><Id>1</Id><Name>abc</Name></ChildNode> <ChildNode? xmlns:a="http://www.google.com"><Id>2</Id><Name>def</Name></ChildNode>
</RootNode> Please help.

Powered by Google Project Hosting