Anybody? Pls help...
Michal
> -----Original Message-----
> From: Grzemowski, Michal
> Sent: Tuesday, July 20, 2004 10:47 PM
> To: [EMAIL PROTECTED]
> Subject: [castor-user] Problem with unmarshalling of date fields still
> there?
>
>
> Hi,
>
> I seem to have a similar problem to those:
> http://hypermail.linklord.com/castor-dev/2003/Oct/1612.html
> http://hypermail.linklord.com/castor-dev/2003/Nov/1731.html
>
> It is also reported to be corrected:
> http://www.castor.org/changelog.html
>
> Can you please help?
>
> I have the following situation:
> - Java class is being mapped both to MySQL database and to
> XML. Therefore I cannot use the workaround - setting the type
> to string.
> - Data is being loaded from the DB, marshaled to XML and
> unmarshaled back.
>
> The following Exception is being thrown during unmarshalling:
>
> toString: org.xml.sax.SAXException: unable to add
> 'departDate' to <LFSMarkets> due to the following exception:
> >>>--- Begin Exception ---<<<
> java.lang.IllegalStateException: Invalid dateTime format: 2004-08-03
> at
> org.exolab.castor.xml.handlers.DateFieldHandler.setValue(DateF
> ieldHandler.java:238)
> at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHan
> dler.java:970)
> at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHan
> dler.java:1038)
>
> The class:
> public class LFSMarkets {
> (...)
> public java.sql.Date departDate;
> public java.sql.Date returnDate;
> }
>
> The mapping:
> <mapping>
> <include href="Mapping.LFSRetrievers.xml"/>
> <class name="com.sabre.dss.comparator.LFSMarkets"
> identity="searchTime marketOrig marketDest advPurchase satNightStay">
> <map-to table="LFSMarkets" xml="LFSMarkets"/>
> (...)
> <field name="departDate" type="java.sql.Date"
> direct="true" handler="com.sabre.dss.comparator.DateHandler">
> <sql name="DepartDate" type="date"/>
> <bind-xml name="departDate" node="element"/>
> </field>
> <field name="returnDate" type="java.sql.Date"
> direct="true" handler="com.sabre.dss.comparator.DateHandler">
> <sql name="ReturnDate" type="date"/>
> <bind-xml name="returnDate" node="element"/>
> </field>
> (...)
> </class>
> </mapping>
>
> The handler:
> package com.sabre.dss.comparator;
> public class DateHandler extends GeneralizedFieldHandler {
> public Object convertUponGet(Object arg0) {
> Date date = (Date)arg0;
> String str = new String(date.toString());
> return str;
> }
> public Object convertUponSet(Object arg0) {
> AnyNode node = (AnyNode) arg0;
> String str = node.getStringValue();
> Date ret = Date.valueOf(str);
> return ret;
> }
> public Class getFieldType() {
> return java.sql.Date.class;
> }
> }
>
> The usage:
> org.exolab.castor.xml.Unmarshaller un = new
> org.exolab.castor.xml.Unmarshaller();
> un.setValidation(true);
> InputSource inS = new InputSource(inStr);
> Mapping map = new Mapping();
> FileInputStream fis = new
> FileInputStream("mapping.xml");
> InputSource is = new InputSource(fis);
> map.loadMapping(is);
> un.setMapping(map);
>
> Object obj = un.unmarshal(inS);
>
> Thanks,
>
> Michal
>
> --
> Michal Grzemowski
> Programmer/Analyst
>
> Sabre Polska Sp z o.o.
> ul. Cystersow 13A
> 31-553 Krakow, Poland
>
> tel: +48 12 295 9056
> fax: +48 12 295 9001
> ----------------------
>
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user