Hi,
In my project I am using the following in
castor mapping xml file
<field name="eventtime"
type="java.sql.Timestamp"
handler="org.exolab.castor.xml.handlers.SQLTimestampFieldHandler">
handler="org.exolab.castor.xml.handlers.SQLTimestampFieldHandler">
When I try to Marshal (write to xml file) the Timestamp field I
have no problem, castor properly writes to xml file as follows
<eventtime>2005-08-09T03:22:48.107-04:00</eventtime>
But when I try to read this(Unmarshal) I am getting the following
exception
java.lang.IllegalArgumentException: Type conversion error: could
not set value o
f [EMAIL PROTECTED] with value of type java.util.Date
at org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandl
erImpl.java:512)
at org.exolab.castor.xml.handlers.DateFieldHandler.setValue(DateFieldHan
dler.java:242)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.ja
va:1066)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.ja
va:1134)
at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLVa
lidator.java:1550)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.disp
atch(XMLDocumentScanner.java:1149)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
canner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:657)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:565)
at main.main(main.java:32)
f [EMAIL PROTECTED] with value of type java.util.Date
at org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandl
erImpl.java:512)
at org.exolab.castor.xml.handlers.DateFieldHandler.setValue(DateFieldHan
dler.java:242)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.ja
va:1066)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.ja
va:1134)
at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLVa
lidator.java:1550)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.disp
atch(XMLDocumentScanner.java:1149)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentS
canner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:657)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:565)
at main.main(main.java:32)
I extended SQLTimestampFieldHandler and overriden
convertUponSet to see how the Timestamp value is prased. The value printed in
the console is Date format. While UnMarshalling castor by default marshalls it
as Date. Is there any work around for this. I am using castor-0.9.7. As
this is very critical for my project if anyone knows the answer please let me
know.
import
org.exolab.castor.xml.handlers.SQLTimestampFieldHandler;
public class ERSQLTimestampFieldHandler extends
SQLTimestampFieldHandler{
public
ERSQLTimestampFieldHandler(){
super();
}
super();
}
public java.lang.Object convertUponSet(java.lang.Object
value){
System.out.println("convertUponSet >>" + value);
return super.convertUponSet(value);
System.out.println("convertUponSet >>" + value);
return super.convertUponSet(value);
}
}
Thanks
-Mothy
Confidentiality Notice The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. If you are not the intended recipient, please notify the sender at Wipro or [EMAIL PROTECTED] immediately and destroy all copies of this message and any attachments. |