|
Usage
FlexXB usage
Featured Using the FlexXB libraryTo serialize an object to xml: To deserialize a received xml to an object, given the object's class: To register a custom annotation, subclass of com.googlecode.serializer.flexxb.Annotation: 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: 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: 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 classesThere 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. | |
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).
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).
Ah silly me, i've spent hours fiddeling with custom built type-descriptors while the solution is so simple, processTypes did the trick, thanks :)
Need to deserialize a xml with the following structure: <Addresses>
</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?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.
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.
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
You have to define the namespace references as annotations on the class. For example:
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.
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">
</RootNode> Unfortunately, it is now appearing as : <RootNode> </RootNode> Please help.