How do I represent dates without the timezone using Apache CXF?

Jared picture Jared · May 26, 2011 · Viewed 24.2k times · Source

I have a WSDL that specifies an element's type to be xs:date.

When I use Apache CXF to generate the Java classes, it renders the variable as an javax.xml.datatype.XMLGregorianCalendar (all good so far).

When CXF renders an XML document containing this, it renders it in this form (where -06:00 represents the time zone):

2000-01-18-06:00

How can I configure CXF not to render the timezone?

Answer

Filip picture Filip · Aug 18, 2011
GregorianCalendar gcal = new GregorianCalendar();
start = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
start.setTimezone(DatatypeConstants.FIELD_UNDEFINED);

Don't ask me why in every bit of the sane logic - when marshalling the XMLgregorianCalendar to xs:date it retains the time zone.

I always thought - the time zone could be more applicable to xs:dateTime, but what I know ... about types.

For me, it doesn't make sense to have the time zone by default, for a xs:date type and this is a problem in the marshalling logic.