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?
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.
To complete Filip answer (thanks to him!), maybe it will help some of you ...
I had to declare a new XmlAdapter on the concern field date with the annotation @XmlJavaTypeAdapter
public class YourDTO {
// ...
@XmlElement
@XmlSchemaType(name = "dateTime")
@XmlJavaTypeAdapter(type = XMLGregorianCalendar.class, value = XmlDateAdapter.class)
public Date yourDate;
// ...
}
The adapter
public class XmlDateAdapter extends XmlAdapter<XMLGregorianCalendar, Date> {
@Override
public XMLGregorianCalendar marshal(Date date) throws Exception {
GregorianCalendar gcal = new GregorianCalendar();
gcal.setTime(date);
XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
xmlDate.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
return xmlDate;
}
// ...
SOAP message date format before
2017-04-18T00:00:00+02:00
SOAP message date format after
2017-04-18T00:00:00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With