Hi Jessica,
I haven't seen that problem before. Is it possible for you to send me a
working (ie compilable and demonstrates the problem) test case which I
can run locally?
--Keith
Jessica Perry Hekman wrote:
Hi all. I have a class which has a method (getCurrency()) which returns
type java.util.Currency. The doc seems to suggest that writing a custom
field handler is the way to proceed, and provides good instruction on how
to do so. I created:
package com.ingenta.ics.api.rest.product;
import org.exolab.castor.mapping.GeneralizedFieldHandler;
import org.exolab.castor.mapping.FieldDescriptor;
import java.util.Currency;
/**
* The FieldHandler for the Currency class
**/
public class CurrencyFieldHandler
extends GeneralizedFieldHandler
{
public CurrencyFieldHandler() {
super();
}
public Object convertUponGet(Object value) {
if (value == null) return null;
Currency currency = (Currency)value;
return currency.getCurrencyCode();
}
public Object convertUponSet(Object value) {
return Currency.getInstance((String)value);
}
public Class getFieldType() {
return Currency.class;
}
public Object newInstance( Object parent )
throws IllegalStateException
{
//-- Since it's marked as a string...just return null,
//-- it's not needed.
return null;
}
}
and in the XML:
<class name="com.ingenta.ics.ecommerce.api.item.Price">
<map-to xml="price"/>
<field name="id" type="com.ingenta.ics.item.Id" />
<field name="amount" type="big-decimal"/>
<field name="currency" type="string"
handler="com.ingenta.ics.api.rest.product.CurrencyFieldHandler"/>
</class>
Now, marshalling works beautifully. Unmarshalling gives me:
1) testProduct(com.ingenta.ics.api.item.ProductMarshallingTest)java.lang.NullPointerException at
org.exolab.castor.xml.util.XMLFieldDescriptorImpl.hashCode(XMLFieldDescriptorImpl.java:416)
at java.util.HashMap.hash(HashMap.java:261)
at java.util.HashMap.containsKey(HashMap.java:339)
I am not sure what's going on -- was I supposed to implement hashCode?
Castor's doc doesn't say so. Is this error familiar to anyone?
Thanks in advance,
Jessica
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------