Issue 53: XMLSerializer doesn't support xsi:type with namespace xsi:type="a:ItemA"
Status:  Verified
Owner:
Closed:  Sep 2011
Reported by domdelor...@gmail.com, Sep 21, 2011
The current xsi:type support doesn't support namespaces  (E.g. <property xsi:type="a:ItemA"></property>)

Basically the following xml (based off the existing xsiType tests in FlexXBTests) cannot be serialized/deserialized using FlexXB due to several minor bugs listed further down the page:

<data id="1" xmlns:a="http://test.com/xsiNS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<a:property xsi:type="a:ItemA">
		<a:element>test</a:element>
	</a:property>
	<a:members>
		<a:listItem xsi:type="a:ItemA">
			<a:element>test a</a:element>
		</a:listItem>
		<a:listItem xsi:type="a:ItemB">
			<a:element>test b</a:element>
		</a:listItem>
	</a:members>
</data>;

I've created patch for trunk (r724) containing addition tests, and fixes to the xml serializers to support namespaces with xsiTypes.

I hope this makes identifying and correcting the issues as straight forward as possible (if not - i've also attached a zip just containing the modified files covered by the patch(FlexXB_trunk_r724.zip)

What steps will reproduce the problem?

1. Apply supplied patch to root of trunk and compile (tests should fail if core classes NOT patched, tests should pass if core classes ARE patched)

It includes changes to the following classes:
	FlexXB/src/main/flex/com/googlecode/flexxb/xml/XmlDescriptionContext.as
	FlexXB/src/main/flex/com/googlecode/flexxb/xml/serializer/XmlArraySerializer.as
	FlexXB/src/main/flex/com/googlecode/flexxb/xml/serializer/XmlElementSerializer.as

And the following test classes:
	FlexXBTest/src/main/flex/com/googlecode/flexxb/XmlSerializerTest.as
	FlexXBTest/src/main/flex/com/googlecode/testData/xsi/BaseItem.as
	FlexXBTest/src/main/flex/com/googlecode/testData/xsi/ItemA.as
	FlexXBTest/src/main/flex/com/googlecode/testData/xsi/ItemB.as
	FlexXBTest/src/main/flex/com/googlecode/testData/xsi/Main.as
	FlexXBTest/src/main/flex/com/googlecode/flexxb/annotation/VersioningTest.as

What version of the product are you using? On what operating system?

Identified in FlexXB 2.2.0, tests and solution applied to trunk (rev 724)

Please provide any additional information below.

To patch this issue i created several additional tests that rely on the same xsi test classes already used in FlexXBTest (I added additional metadata to the classes in com.googlecode.testData.xsi using FlexXB versioning (version="xsiNS"). This uncovered several other minor bugs relating to the version attribute not always being propagated correctly (they have also been addressed in the patch)

1. xml serializer ignores XmlClass namespace prefix when serializing xsi:type to xml (e.g. xsi:type="ItemA" should be xsi:type="a:ItemA") .

See XmlElementSerializer.serializeObject

2. deserializing with xsi:type fails due to XmlDescriptionContext.getClassByAlias looking for literal string match with alias "a:ItemA"  rather than checking for "ItemA" with matching namespace

See XmlDescriptionContext.getIncomingType for solution (and comments for caveat)

3. xml serializer ignores namespace on XmlArray memberName when setXsiType="true"

See XmlArraySerializer.serializeObject in patch

I have read recommendations in the google groups site (http://groups.google.com/group/flexxb/browse_thread/thread/46aa230042b739a0/5381bfd1e1d69e3a) that recommends removing memberName so that FlexXB uses child XmlClass alias/namespace instead.

However this isn't possible when using xsi:type as removing memberName results in each child element using the sub class alias rather than a generic element name.

E.g.

Current output when  memberName is not specified:

XmlArray(alias="members", setXsiType="true", getRuntimeType="true", namespace="a")]
public var list : Array;

<a:members>
	<a:ItemA xsi:type="a:ItemA">
		<element>test a</element>
	</a:ItemA>
	<a:ItemB xsi:type="a:ItemB">
		<element>test b</element>
	</a:ItemB>
</a:members>

Current output if memberName is specified:

[XmlArray(alias="members", memberName="listItem", setXsiType="true", getRuntimeType="true", namespace="a")]
public var list : Array;

results in 
<a:members>
	<listItem xsi:type="a:ItemA">
		<element>test a</element>
	</listItem>
	<listItem xsi:type="a:ItemB">
		<element>test b</element>
	</listItem>
</a:members>


Expected output when memberName specified

<a:members>
	<a:listItem xsi:type="a:ItemA">
		<element>test a</element>
	</a:listItem>
	<a:listItem xsi:type="a:ItemB">
		<element>test b</element>
	</a:listItem>
</a:members>



4. XmlElementSerializer.getValue doesn't provide mechanism for serializers to pass version attribute through to children 

See patch for updates in XmlElementSerializer and XmlArraySerializer to pass version data through to getValue

Note: This fix highlighted a incorrect assertion in com.googlecode.flexxb.annotation.VersioningTest (line 71) where mock XML (line 62) contained an xml element mapped to the default version rather than the version being detected.

I've included the update to this test in the patch.






patch.txt
15.0 KB   View   Download
FlexXB_trunk_r724.zip
30.9 KB   Download
Sep 22, 2011
Project Member #1 alex.id....@gmail.com
(No comment was entered for this change.)
Status: Accepted
Labels: Milestone-2.3.0
Sep 22, 2011
Project Member #2 alex.id....@gmail.com
Hey, wonderful job! I'll include this in the codebase
Sep 22, 2011
Project Member #3 alex.id....@gmail.com
(No comment was entered for this change.)
Status: Fixed
Sep 22, 2011
Project Member #4 alex.id....@gmail.com
(No comment was entered for this change.)
Labels: -Type-Defect Type-Enhancement
Apr 14, 2012
Project Member #5 alex.id....@gmail.com
(No comment was entered for this change.)
Status: Verified
Owner: alex.id....@gmail.com