Is it possible to map an attribute containing a decimal number to a
field whose type is a subclass of BigDecimal?  When I try to do so,
I get an IllegalArgumentException:

java.lang.IllegalArgumentException: Type conversion error: could not set value of 
BaseLoanAmount(com.example.types.Amount) with value of type java.lang.String

Any ideas on how to do this in Castor?  Thanks for any tips.

Ken

ps. Details (mapping file, code for the BigDecimal subclass (Amount),
and the stack trace) follow.  The fragments work with BaseLoanAmount
removed from the mapping file, so the context, including a mapping
directly to BigDecimal (PurchasePrice), works fine.


<mapping>
  <class name="com.example.types.Amount"
         verify-constructable="false">
  </class>
  <class name="com.example.interfaces.Request">
    <map-to xml="REQUEST"/>
    <field name="ChannelType"
           type="com.example.types.ChannelType">
      <bind-xml name="Channel" node="attribute"/>
    </field>
    <field name="SupplierID"
           type="java.lang.String">
      <bind-xml name="SupplierID" node="attribute"/>
    </field>
    <field name="NumberOfUnits"
           type="integer">
      <bind-xml name="PropertyFinancedNumberOfUnits" node="attribute"/>
    </field>
    <field name="PurchasePrice"
           type="java.math.BigDecimal">
      <bind-xml name="PurchasePriceAmount" node="attribute"/>
    </field>
    <field name="BaseLoanAmount"
           type="com.example.types.Amount">
      <bind-xml name="BaseLoanAmount" node="attribute"/>
    </field>
  </class>
</mapping>

package com.example.types;
import java.math.BigDecimal;
import java.math.BigInteger;

public class Amount extends BigDecimal {
  public Amount(String val) {
    super(val);
  }
  public Amount(double val) {
    super(val);
  }
  public Amount(BigInteger val) {
    super(val);
  }
  public Amount(BigInteger unscaledVal, int scale) {
    super(unscaledVal, scale);
  }
}

Caused by: java.lang.IllegalArgumentException: Type conversion error: could not set 
value of BaseLoanAmount(com.example.types.Amount) with value of type java.lang.String
        at 
org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandlerImpl.java:474)
        at 
org.exolab.castor.xml.UnmarshalHandler.processAttribute(UnmarshalHandler.java:2779)
        at 
org.exolab.castor.xml.UnmarshalHandler.processAttributes(UnmarshalHandler.java:2479)
        at 
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1577)
        at 
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1292)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
        at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown 
Source)
        at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
        at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
        at 
org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown
 Source)
        at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
 Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:605)



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

Reply via email to