Java: JAXB: Marshelling from JAXBElement <Calendar> to xs: date not correct
I have a problem with JAXB. I created my Java classes via xjc (using xsd schema) and has global binding for XML-Datatypes xs: date xs: dateTime and xs: time to java.util.Calendar using parsing and printing method. A.
Everything worked fine until I put some xs: date fields as nillable. Xjc creates JAXBElement wrappers for these properties. If these fields become unmarshaled, the date is printed, including time information that leads to validation errors.
Is there any way to get Marshaller to convert it to xs: date instead of xs: dateTime?
Is it possible to specify a binding for those fields that receive a special XMLAdapater that converts these fields?
The property inside the Java class is as follows:
@XmlElementRef(name = "dateField", namespace = "namespace", type = JAXBElement.class) protected JAXBElement<Calendar> dateField;
and the corresponding xsd looks like
<xs:element name="dateField" minOccurs="0" nillable="true" type="xs:date" />
Can anybody help me?
Thanks and best regards,
Arne
Do you really need to map the Calendar inside JAXBElement ?, would it be wrong to use XMLGregorianCalendar instead (and then you can convert it to Date)?