Deserializing using custom serializer

17 views
Skip to first unread message

Alexey Kuznetsov

unread,
Jul 27, 2011, 4:06:26 AM7/27/11
to FxWorks
Hello!
I try to deserialize some xml. I wrote custom serializer class
MaterialSerializer extending BaseSerializer with overrided function
deserialize();
Class for deserializing:
[XmlClass(alias="flow", uri="http://www.imsglobal.org/xsd/
ims_qtiasiv1p2")]
public class Flow {

[MaterialElement]
public var material:CustomMaterial;

[ArrayElementType("com.gmat.model.qti.Flow")]
[XmlArray(alias="flow", type="com.gmat.model.qti.Flow")]
public var flowArray:Array;

public function Flow() {
}
}

I done custom annotation:
public class MaterialElement extends XmlMember
I register custom annotation with context:
var context:DescriptionContext =
FxBEngine.instance.getXmlSerializer().context;
context.registerAnnotation("MaterialElement", MaterialElement,
MaterialSerializer);

But when method deserialize of custom serializer invokes in its
argument named serializedData there is an xml contains not only
<material> element and its children, but larger xml like this:
<flow width="700" xmlns="http://www.imsglobal.org/xsd/ims_qtiasiv1p2"
xmlns:pearsonvue="http://www.vue.com/schemas" xmlns:vantage="http://
www.vantage.com/schemas/vantage">
<flow border="1,1,1,1" inset="0,0,0,0" orientation="horizontal">
<flow inset="0,0,0,0" width="140">
<flow height="43" inset="2,2,0,0">
<material>
<mattext>
<p align="center" style="white-space: pre-wrap; ">Must
happen in the location</p>
</mattext>
</material>
</flow>
<flow inset="0,0,0,0" orientation="vertical">
<response_lid ident="211:000508-RO-R01" rcardinality="single">
<render_choice>
<flow_label border="1,0,0,0" height="24" inset="4,60,0,0">
<response_label ident="A" valign="middle"/>
</flow_label>
<flow_label border="0,0,0,0" height="24" inset="4,60,0,0">
<response_label ident="B" valign="middle"/>
</flow_label>
</render_choice>
</response_lid>
</flow>
</flow>
<flow inset="0,0,0,0" width="140">
<flow border="0,1,0,0" height="43" inset="2,2,0,0">
<material>
<mattext>
<p align="center" style="white-space: pre-wrap; ">Must not
happen in the

location</p>
</mattext>
</material>
</flow>
<flow inset="0,0,0,0" orientation="vertical">
<response_lid ident="211:000508-RO-R02" rcardinality="single">
<render_choice>
<flow_label border="1,1,0,0" height="24" inset="4,60,0,0">
<response_label ident="A" valign="middle"/>
</flow_label>
<flow_label border="0,1,0,0" height="24" inset="4,60,0,0">
<response_label ident="B" valign="middle"/>
</flow_label>
</render_choice>
</response_lid>
</flow>
</flow>
<flow inset="0,0,0,0" orientation="vertical" width="418">
<flow border="0,1,0,0" height="43" inset="10,2,0,0">
<material>
<mattext>
<p align="center" style="white-space: pre-wrap;
">Activities of the members of

the species</p>
</mattext>
</material>
</flow>
<flow border="1,1,0,0" height="24" inset="2,5,0,0">
<material>
<mattext>Sleeping</mattext>
</material>
</flow>
<flow border="0,1,0,0" height="24" inset="2,5,0,0">
<material>
<mattext>Occupying the location multiple times</mattext>
</material>
</flow>
</flow>
</flow>
<flow inset="0,0,0,0"/>
</flow>

I should do some things with content of <material> in serializer but I
can't cause serializer is called once for the whole part of xml like
above not for each <material> entry.
Question: Is it possible to call serializer for each element entry and
get in serializedData argument only content of element like below?
<mattext>
<p align="center" style="white-space: pre-wrap; ">Must happen in
the location</p>
</mattext>

Sorry for complex explanation, may be i didn't properly understand
using custom serializers.

Alexutz

unread,
Jul 27, 2011, 4:25:31 AM7/27/11
to FxWorks
Hi Alexey,

Well, if you've built your own annotation serializer then you should
be able to do anything you want. If you still don't get the hang of
it, maybe you could send me a sample project with your custom
serializer at work and the way xml should really look and I could take
a look into it.

Alex

Alexutz

unread,
Jul 27, 2011, 4:28:29 AM7/27/11
to FxWorks
You get the full parent xml in the deserializer because it's the
annotation deserializer's job to extract the proper child. XmlNAme of
the child may be different or it should be determined at runtime. The
best example would be the XMlelementSerializer class. Take a look at
it and you should see how it works.
> > using custom serializers.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages