You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Pa...@swisscom.com on 2006/05/17 16:35:03 UTC
CalendarSerializer dateTime bug?
Hi all
I tried to serialize a dateTime where I have a Calendar with date
"0001-01-01"
When Axis serializes it would use UTC. All ok.
As im located central europe my date is CET and it creates the UTC -1
Hour.
Now I get the value: "0001-12-31T23:00:00.000Z"
Should it not add additionally the sign "-" in front of, so that I would
receive "-0001-12-31T23:00:00.000Z"?
The problem is in deserialisation where I get the date "0002-01-01".
XSD-Type in WSDL
<complexType name="DateRange">
<attribute name="start" type="dateTime" use="required"/>
<attribute name="end" type="dateTime" use="required"/>
</complexType>
Using Axis 1.2.1 (but same behavior in higher versions, see
CalendarSerializer in CVS).
The DateSerializer checks with an internal calendar for BC or AD, but I
do not understand how
there the calendar should go BC..., perhaps when the computer time is
BC?
Should the CalendarSerializer not check the value (should be a
java.util.Calendar) if it is
BC or AD and add a "-"?
Thanks
Patrick
-------
public class CalendarSerializer implements SimpleValueSerializer {
public String getValueAsString(Object value,
SerializationContext context) {
Date date = value instanceof Date ? (Date) value :
((Calendar) value).getTime();
// Serialize including convert to GMT
synchronized (zulu) {
// Sun JDK bug
http://developer.java.sun.com/developer/bugParade/bugs/4229798.html
return zulu.format(date);
}
}
}
public class DateSerializer implements SimpleValueSerializer {
private static Calendar calendar = Calendar.getInstance();
public String getValueAsString(Object value,
SerializationContext context) {
StringBuffer buf = new StringBuffer();
synchronized (calendar) {
if(value instanceof Calendar) {
value = ((Calendar)value).getTime();
}
if (calendar.get(Calendar.ERA) == GregorianCalendar.BC) {
buf.append("-");
calendar.setTime((Date)value);
calendar.set(Calendar.ERA, GregorianCalendar.AD);
value = calendar.getTime();
}
buf.append(zulu.format((Date)value));
}
return buf.toString();
}
}