Hi, I would be grateful if anyone has any advice regarding the following issue.
When using XML code generated classes, I am able to unmarshal a document containing an element that is an extension of the target type. However, the resulting object has the runtime type of the target (base) type, and so any extended values are unavailable. To illustrate, a simple example follows. The schema defines a base ProductType, an extension ShirtType, and dictates that an inventory has a product: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="InventoryType"> <xsd:sequence> <xsd:element name="product" type="ProductType"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="ProductType"> <xsd:sequence> <xsd:element name="number" type="xsd:integer"/> <xsd:element name="name" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="ShirtType"> <xsd:complexContent> <xsd:extension base="ProductType"> <xsd:sequence> <xsd:element name="size" type="xsd:integer"/> <xsd:element name="color" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:element name="inventory" type="InventoryType"/> </xsd:schema> The code generator defines abstract classes for the following complex types: - InventoryType - ProductType - ShirtType (extends ProductType) The code generator defines the following element classes: - Inventory - Product Note that these classes do not cater for the instantiation of an instance of ShirtType. In an instance document, a shirt can be substituted for the base product type, with xsi:type indicating the substitution: <?xml version="1.0" encoding="UTF-8"?> <inventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="inventory.xsd"> <product xsi:type="ShirtType"> <number>999</number> <name>Test Shirt</name> <size>40</size> <color>Blue</color> </product> </inventory> Invoking getProduct() on the Unmarshalled Inventory instance returns an object with a runtime type of Product, resulting in a loss of type information. Is there any way to have getProduct() return an instance of ShirtType in this scenario? The above example is purely for illustrative purposes. The actual problem domain involves a much more complicated schema, which is prone to change, and outside of my control. My preferred approach, if possible, is to rely solely on the generated classes, and to avoid introducing custom mappings. Any thoughts would be greatly appreciated. Regards, Nigel --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

