Title: Message
 
I just discovered that we have manually turned off the creation of the xsi:type in the final document.  Once I removed this, I was able to marshall/unmarshall correctly.
 
Thanks,
 
Matt
-----Original Message-----
From: Emerson, Matt
Sent: Wednesday, March 09, 2005 6:58 PM
To: [email protected]
Subject: [WARNING: This message originated from outside of Fidelity] [castor-user] Using Interfaces during marshalling/unmarshalling


I have created two classes and 1 interface: Product, SubProduct, and SubProductIF
They are as follows:

Public class Product

        private SubProductIF sample

        public Product()

        public void setSample(SubProductIF data) { this sample = data; }
        public SubProductIF getSample() { return this.sample; }
}

Public class SubProduct implements SubProductIF
{
        private String name;
        private String value;

        public SubProduct() {}

        public void setName(String data) { this.name = data; }
        public void set Value(String data) { this.value = data; }

        public String getName() { return this.name; }
        public String getValue() { return this.value; }
}

And the interface:
public interface SubProductIF
{
    public void setName(String pValue);
    public String getName();
   
    public void setValue(String pValue);
    public String getValue();
}

The mapping is as follows:
<mapping>
        <description>Description of the mapping for the Product Class</description>
        <class name="com.fmr.cfit.matt.castor.Product">
                <map-to xml="WrapperProductClass"></map-to>            
                <field name="sample" type="com.fmr.cfit.matt.castor.SubProductIF">
                        <bind-xml name="sample_product" node="element"/>
                </field>
        </class>
        <class name="com.fmr.cfit.matt.castor.SubProduct">
                <map-to xml="sub_product"></map-to>
                <field name="name" type="java.lang.String">
                        <bind-xml name="name" node="attribute"/>
                </field>
                <field name="value" type="java.lang.String">
                        <bind-xml name="value" node="element"/>
                </field>
        </class>
</mapping>

When I marshall the class, everything works fine.  However, when I unmarshall it, it throws an error because it can't find the constructor for SubProduct.  Reading the documentation, it says to use the xsi:type attribute…but that seems like something that has to be added to the final marshalled class.  Since I want this to be an identity transformation, if I can't do that automatically, it is not very useful.  Does anyone have any ideas how I could make this into an two-way transform using interfaces?

Thanks,

Matt

The Error:

#endElement: class
#endElement: mapping
 #startElement: WrapperProductClass
 #startElement: sample_product

 unable to instantiate a new type of: com.fmr.cfit.matt.castor.SubProductIF org.xml.sax.SAXException: unable to instantiate a new type of: com.fmr.cfit.matt.castor.SubProductIF

        void org.exolab.castor.xml.UnmarshalHandler.startElement(java.lang.String, java.lang.String, org.exolab.castor.xml.AttributeSet)                UnmarshalHandler.java:2096

        void org.exolab.castor.xml.UnmarshalHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)          UnmarshalHandler.java:1292

        void org.apache.xerces.parsers.SAXParser.startElement(org.apache.xerces.utils.QName, org.apache.xerces.framework.XMLAttrList, int)              SAXParser.java:1371

        void org.apache.xerces.validators.common.XMLValidator.callStartElement(org.apache.xerces.utils.QName)           XMLValidator.java:840

        boolean org.apache.xerces.framework.XMLDocumentScanner.scanElement(org.apache.xerces.utils.QName)               XMLDocumentScanner.java:1852    boolean org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(boolean)              XMLDocumentScanner.java:1233    boolean org.apache.xerces.framework.XMLDocumentScanner.parseSome(boolean)               XMLDocumentScanner.java:380     void org.apache.xerces.framework.XMLParser.parse(org.xml.sax.InputSource)

                XMLParser.java:908
        java.lang.Object org.exolab.castor.xml.Unmarshaller.unmarshal(org.xml.sax.InputSource)
                Unmarshaller.java:605
        java.lang.Object org.exolab.castor.xml.Unmarshaller.unmarshal(java.io.Reader)
                Unmarshaller.java:513   void com.fmr.cfit.matt.castor.TestCastor.runTest2()
                TestCastor.java:76      void com.fmr.cfit.matt.castor.TestCastor.main(ja

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to