Hi Keith. You'd think I could get you a test case. But when I put one
together, it didn't break. :P I conclude that there is something at fault
in the massive system that my small piece of work is embedded in, so I'll
keep investigating that. If I get a useful test case, I'll definitely send
it on. Thank you!
Jessica
On Wed, Nov 30, 2005 at 10:57:36PM -0600, Keith Visco wrote:
> 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]
> -------------------------------------------------
>
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------