Java: JAXB: Marshelling of JAXBElement<Calendar> to xs:date not correct

I have a problem using JAXB. I've created my Java Classes via xjc (using an xsd-schema) and has a global binding for the XML-Datatypes xs:date xs:dateTime and xs:time to java.util.Calendar with parse and print method.

Everything works fine until I marked some xs:date fields as nillable. The xjc creates JAXBElement wrappers for those properties. If these fields get unmarshaled the date is printed out including the time information which leads to validation errors.

Is there a possibilty to force the Marshaller to convert it to xs:date instead of xs:dateTime?

Can I specify a binding for those fields which gets a special XMLAdapater ewhich converts those fields?

The property inside the Java-Class looks like that:

@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 someone help me please?

Thanks and best regards,

Arne


您是否真的需要将日历映射到JAXBElement?中,而不是使用旧版XMLGregorianCalendar(然后您可以将其转换为日期)?

链接地址: http://www.djcxy.com/p/18740.html

上一篇: 通过ASMX web servcie函数读取SOAP XML

下一篇: Java:JAXB:JAXBElement <Calendar>的Marshelling转换为xs:date不正确