Hi Faisal, Can you send me your complete example (or a sample one which demonstrates the problem) and I'll try debugging it here when I have an opportunity, otherwise it's a bit difficult to determine what the problem may be without actually seeing it first hand.
Thanks, --Keith Faisal Shoukat wrote: > > Thanks Keith, > > I have tried type Id both ways as an element and an attribute. The xml > shown in this email was just one of them. I got the NPException both > ways. Any other suggestions to fix this would be greatly appreciated. I > agree with you from the mapping file the item class should be getting > created but it does not seem to be. From the item class I only require > two attributes which I have defined in my mapping file. Is it because I > have not defined the other fields within the item class that it is not > able to create an item object? > > Thanks in advance > Faisal > > -----Original Message----- > From: Keith Visco [mailto:[EMAIL PROTECTED] > Sent: 22 August 2003 06:58 > To: [EMAIL PROTECTED] > Subject: Re: [castor-dev] unmarshalling not building objects correctly > Help!!! > > Hi Faisal, > > The Item class should be getting created, since the setLeadItem method > is being called. Normally this method isn't called with a null object. > However, my guess is that the problem is with the type-id field. You > have specified that the type-id should be an attribute, but in your XML > you have it as an element. So Castor is probably not matching this node > with it's proper field. And in your setter you are getting an NPE > because typeId isn't being unmarshalled. > > --Keith > > -------- Original Message -------- > Subject: [castor-dev] unmarshalling not building objects correctly > Help!!! > Date: Thu, 21 Aug 2003 17:00:00 +0100 > From: "Faisal Shoukat" <[EMAIL PROTECTED]> > Reply-To: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > > Hi All, > > I have created a mapping file to marshall an object and this works fine > and it creates the XML required.However when I come to unmarshall this > XML string back to the java object it throws a null pointer exception > where it tells me that it cannot execute the set method because of the > null pointer. > > The xml I have created looks like: > > <family resource-id="10001" typeId="22"> > > <start-date>2003-08-21T16:28:40.999+01:00</start-date> > > <end-date>2500-01-31T00:00:00.000Z</end-date> > > <lead-item resource-id="10001804"> > > <type-id>55</type-id> > > </lead-item> > > <members resource-id="10001804"> > > <type-id>55</type-id> > > </members> > > <members resource-id="10001805"> > > <type-id>55</type-id> > > </members> > > </family> > > Note that lead item has a resource id and type id. > > My mapping file looks like this: > > <?xml version="1.0" encoding="UTF-8"?> > > <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version > 1.0//EN" "http://castor.exolab.org/mapping.dtd"> > > <mapping> > > <class name="family" extends="resource" > > auto-complete="false"> > > < > > <map-to xml="pricing-family"/> > > <field name="resourceId" type="long" required="true" > > direct="false" transient="false"> > > <bind-xml name="resource-id" node="attribute"/> > > </field> > > <field name="typeId" type="int" required="true"> > > <bind-xml name="typeId" node="attribute"/> > > </field> > > <field name="name" type="string" required="true" direct="false" > transient="false"> > > <bind-xml name="name" node="attribute"/> > > </field> > > <field name="startDate" type="date" required="true" > > direct="false" transient="false"> > > <bind-xml name="start-date" node="element"/> > > </field> > > <field name="endDate" type="date" required="true" direct="false" > transient="false"> > > <bind-xml name="end-date" node="element"/> > > </field> > > <field name="leadItem" > > type=" Item" > > required="true" direct="false" transient="false"> > > <bind-xml name="lead-item" node="element"/> > > </field> > > <field name="members" > > type=" Item" > > required="true" direct="false" transient="false" > > get-method="getItems" set-method="setMembers" collection="collection"> > > <bind-xml name="members" node="element"/> > > </field> > > </class> > > <class name=" Item" auto-complete="false"> > > <map-to xml="item"/> > > <field name="resourceId" type="long" required="true" > > direct="false" transient="false"> > > <bind-xml name="resource-id" node="attribute"/> > > </field> > > <field name="typeId" type="int" required="true" > > direct="false" transient="false"> > > <bind-xml name="type-id" node="attribute"/> > > </field> > > </class> > > </mapping> > > The java object I am trying to create has a set lead item method which > does the following: > > public void setLeadItem(Item leadItem) > > { > > this.leadItem = leadItem; > > this.leadItemId = leadItem.getResourceId(); > > this.leadItemTypeId = leadItem.getType().getId(); > > } > > When unmarshalling the XML it throws a null pointer exception: > > exception = org.xml.sax.SAXException: unable to add 'lead-item' to > <pricing-family> due to the following exception: > > >>>--- Begin Exception ---<<< > > java.lang.NullPointerException > > atFamily.setLeadItem(Unknown Source) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j > ava:39) > > atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess > orImpl.java:25) > > atjava.lang.reflect.Method.invoke(Method.java:324) > > atorg.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandle > rImpl.java:463) > > atorg.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.jav > a:803) > > atorg.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1392) > > atorg.apache.xerces.validators.common.XMLValidator.callEndElement(XMLVal > idator.java:1480) > > at > org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatc > h(XMLDocumentScanner.java:1149) > > atorg.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentSc > anner.java:381) > > atorg.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081) > > atorg.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:555) > > atorg.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:487) > > atorg.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:627) > > at > com.retailexp.amp.ejb.auditmanagement.EJBAuditManagementBean.unmarshallM > essage(Unknown > Source) > > at > com.retailexp.amp.ejb.auditmanagement.EJBAuditManagementBean_a9djj3_EOIm > pl.unmarshallMessage(EJBAuditManagementBean_a9djj3_EOImpl.jav > > at > com.retailexp.amp.ejb.auditmanagement.EJBAuditManagementBean_a9djj3_EOIm > pl_WLSkel.invoke(Unknown > Source) > > atweblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362) > > atweblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRe > f.java:114) > > at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313) > > atweblogic.security.service.SecurityServiceManager.runAs(SecurityService > Manager.java:785) > > atweblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java > :308) > > atweblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest. > java:30) > > atweblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153) > > atweblogic.kernel.ExecuteThread.run(ExecuteThread.java:134) > > Can anybody help please?? It seems to me like it is not creating the > item object which is required but I cannot understand why because it is > mapped in the mapping file and should be created.Anybody please????? > > Thanks in advance > > Faisal > > ----------------------------------------------------------- > If you wish to unsubscribe from this mailing, send mail to > [EMAIL PROTECTED] with a subject of: > unsubscribe castor-dev > > ----------------------------------------------------------- > If you wish to unsubscribe from this mailing, send mail to > [EMAIL PROTECTED] with a subject of: > unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
