Hello, 


I'm using Castor version 0.9.5.
I have a class 'Decimal' extending Number, with a constructor taking a String. When 
I'm using Castor with that class, it does not work. When I remove the 'extends 
Number', it works pretty well !


* Here is the xml-mapping :
<?xml version="1.0" encoding="UTF-8"?>
<mapping>
    <class name="Data">
        <map-to xml="data"/>
        <field name="decimal" type="Decimal" direct="true">
            <bind-xml name="numberdata" node="element"/> 
        </field>
    </class>
    
    <class name="Decimal" verify-constructable="false">
        <field name="value" type="string" 
                set-method="%1" get-method="toString">
            <bind-xml node="attribute"/>
        </field>
    </class>
</mapping>


* here is the response when marshalling :
<?xml version="1.0" encoding="UTF-8"?>
<data>
   <numberdata value="12345">12345</numberdata>
</data>


* and here is the exception when unmarshalling :
org.xml.sax.SAXException: unable to add 'numberdata' to <data> due to the following 
exception: 
>>>--- Begin Exception ---<<< 
java.lang.IllegalArgumentException: Type conversion error: could not set value of 
decimal(Decimal) with value of type java.lang.String
        at 
org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandlerImpl.java:474)
        at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:803)
        at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1392)
        at 
org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1180)
        at 
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1201)
        at 
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:952)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:555)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:487)
        at CastorTest.main(CastorTest.java:68)
>>>---- End Exception ----<<< 


* When removing the second number in the xml and unmarshalling, no Decimal is created 
(this xml : 
<?xml version="1.0" encoding="UTF-8"?>
<data>
   <numberdata value="12345"/>
</data>
).



Is there an easy workaround to this (other than removing the 'extends Number' that is) 
?

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

Reply via email to