Okay! I got it breaking :)
The problem appears to occur NOT when I add in the FieldHandler for
java.util.Currency but when I remove these lines
<field name="prices" collection="set"
type="com.ingenta.ics.ecommerce.api.item.Price">
<bind-xml name="price"/>
</field>
and replace them with
<field name="prices" collection="set" container="false"/>
I made that switch in the first place because the Set of Price objects
(each of which contain a Currency) was unmarshalling as null and I
couldn't figure out why. I'll keep investigating that. In the meantime,
though, you can see my test case (which does not use Price objects --
those are too complex -- it uses CurrencyContainer objects for
simplicity's sake) at:
http://pendaran.arborius.net/~jphekman/testcase.tgz
Untar and set your classpath like so
export
CLASSPATH=$CLASSPATH:build/classes:lib/castor-xml.jar:lib/xml-apis.jar:lib/xercesImpl.jar:lib/commons-logging.jar
and then run like so
java com.ingenta.Mapper
and expect to see the error
Exception in thread "main" java.lang.NullPointerException
at
org.exolab.castor.xml.util.XMLFieldDescriptorImpl.hashCode(XMLFieldDescriptorImpl.java:416)
at java.util.HashMap.hash(HashMap.java:261)
...although perhaps all that is unnecessary, and perhaps it is clear to
you what the problem is, now that I know what syntax change caused it.
Thank you very much!
Jessica
On Wed, Nov 30, 2005 at 10:57:36PM -0600, Keith Visco wrote:
> 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]
> -------------------------------------------------
>
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------