Re: [Simple-support] Date
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2007-06-13 17:07:59
|
Hi,
Yes you should be able to serialize and deserialize dates without any trouble. Support for the java.util.Date is not included, as it is a pretty flakey object, that is all but deprecated. I would do something like:
@Root
public class MyObject {
@Element
public MyDate date;
}
@Root
public class MyDate {
@Attribute
private String getTime() {
return System.currentTimeMillis();
}
@Atttribute
private void setTime(long time) {
this.time = time;
}
public Date toDate() {
return new Date(time);
}
}
Which would look something like:
<myObject>
<myDate time="123456789"/>
</myObject>
Of course it may be better to use a string format to perform this like so:
@Root
public class MyObject {
private static final DateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
@Attribute
private String date;
private Date myDate;
@Commit
private void commit() throws Exception {
myDate = formatter.parse(date);
}
@Persist
private void persist() throws Exception {
date = formatter.format(myDate);
}
public void setDate(Date myDate) {
this.myDate = myDate;
}
public Date getDate() {
return myDate;
}
}
This allows XML like so:
<myDate time="Wed, 4 Jul 2001 12:08:56 -0700"/>
I have intentionally avoided supporting java.util.Date as it is such a poor date representation.
Niall
----- Original Message ----
From: "Zaffke, Micholas Mr CIV USA USAREUR" <Mic...@EU...>
To: sim...@li...
Sent: Wednesday, June 13, 2007 9:18:22 AM
Subject: [Simple-support] Date
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;margin-bottom:.0001pt;font-size:12.0pt;font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;text-decoration:underline;}
span.EmailStyle17
{font-family:Arial;color:windowtext;}
_filtered {margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{}
-->
Does Simple have any support for Date data types? My object
holds a java.util.Date but when I persist it to XML the result contains this:
<DATE class="java.sql.Timestamp"/>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
____________________________________________________________________________________
Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545433 |