Can JAX-WS map an XSD date (xs:dateTime) to a Java Calendar?
Can JAX-WS map an XML schema date (xs:dat开发者_开发百科eTime
), including its time zone, to a Java Calendar
?
Yes, it can.
Contract first approach
You need to use the jaxb:javaType
element. There's some general information here and an example of what you need to do here.
Contract last approach
@WebMethod(operationName = "getTest")
public Calendar getTest(@WebParam(name = "input") Calendar input) {
input.roll(Calendar.DAY_OF_YEAR, 1);
return input
}
Will map to:
<xs:complexType name="getTest">
<xs:sequence>
<xs:element name="input" type="xs:dateTime" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getTestResponse">
<xs:sequence>
<xs:element name="return" type="xs:dateTime" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
I would think it would work by default; JAXB (data binder that JAX-WS implementations use) should know how to convert between XML values and java.util.Calendar.
If not, the default date/time datatype used with XML is javax.xml.datatype.XMLGregorianCalendar, which can be converted using method toGregorianCalendar() (which will be of type java.util.GregorianCalendar, a java.util.Calendar subclass). So one possibility is to get data bound to XMLGregorianCalendar, then just convert back/forth when accessing. This can also be automated by using XMLJavaTypeAdapter.
精彩评论