Menu

#132 Bug with Serialization of Derived Types

v2.0
closed-fixed
zsi (169)
5
2006-05-09
2006-05-08
No

OK. I've gone on to my next step, trying to create an instance which
contains a derived type and have its serialization contain all the derived
type information.
But, when it serializes, I get the base type even though I initialize the
element in the instance with a derived type instance.
Remember, my goal is to have a tag which can be any of a number of
different types which derive from the same
base type... thus I don't want to explicitly name any of the derived
types, just the base type, in the element definition for 'test'
at the bottom...

Here's my schema,

<!-- base actor type with no special options -->
<xs:complexType name="BaseActor">
<xs:sequence>
<xs:element name="gui" type="xs:string"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="class" type="xs:string"/>
</xs:complexType>

<xs:complexType name="IfElseActor">
<xs:complexContent>
<xs:extension base="typens:BaseActor">
<xs:sequence>
<xs:element name="parameter" type="typens:parameter"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="port" type="typens:port" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="test">
<xs:sequence>
<xs:element name="actor" type="typens:BaseActor"/>
</xs:sequence>
</xs:complexType>

<xs:element name="test" type="typens:test"/>

the test code:
x = IfElseActor.pyclass()
x._gui = foo"
x._port = ["bar","baz"]
x._parameter = ["bop"]
## Populate the 'test' element
t = test.pyclass()
t._actor = x

s1 = SoapWriter(envelope=False)
s1.serialize(t, typecode=test)
s1.close()

s = s1.dom.toString()
print s

This produces:
<?xml version="1.0" encoding="UTF-8"?>
<ns2:test xmlns:ns1="http://www.w3.org/2001/XMLSchema-
instance" xmlns:ns2="urn:test">
<actor ns1:type="ns2:BaseActor">
<gui ns1:type="ns2:gui" class="foo"/>
</actor>
</ns2:test>

It's showing up as a BaseActor, not an IfElseActor.

Discussion

  • Joshua Boverhof

    Joshua Boverhof - 2006-05-09
    • status: open --> closed-fixed
     
  • Joshua Boverhof

    Joshua Boverhof - 2006-05-09

    Logged In: YES
    user_id=711996

    fixed bug and added unittest.

     

Log in to post a comment.