kaqqao kaqqao - 1 year ago 85
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

(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
in Java.

As you probably know, Axis wraps
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 Source

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

GregorianCalendar gc=new GregorianCalendar(1,0,1);

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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download