kaqqao kaqqao - 23 days ago 10
Java Question

Apache Axis - Calendar instance that gets serialized to 0001-01-01T00:00:00.000Z

I'm using Apache Axis to communicate with a web service written in .Net.

One of the functions in that WS has special handling when it encounters

DateTime.MinDate
(i.e. "0001-01-01"). Now, I'm trying to send this special value to the WS, but there seems to be no equivalent to
DateTime.MinDate
in Java.

As you probably know, Axis wraps
xsd:dateTime
into
Calendar
objects, so I tried sending
new GregorianCalendar(1 ,1 ,1);
but this didn't do the trick. I tried
calendar.setTime(new Date(0))
, I tried many more combinations, but nothing seems to get serialized as

<endDate xsi:type="xsd:dateTime">0001-01-01T00:00:00.000Z</endDate>


which is what I need. Does anyone have any clue how can this be achieved?

Answer

The following will create a GregorianCalendar object that will serialize to the equivalent of DateTime.MinValue.

GregorianCalendar gc=new GregorianCalendar(1,0,1);
gc.setTimeZone(TimeZone.getTimeZone("GMT-0"));

Note the following:

  • The month parameter is zero based, not 1 based.
  • GregorianCalendar defaults to the local time zone, therefore the timezone needs to be adjusted manually.
Comments