我有一个WSDL,它将元素的类型指定为xs:date.
当我使用Apache CXF生成Java类时,它将该变量呈现为javax.xml.datatype.XMLGregorianCalendar(到目前为止都很好).
当CXF呈现包含此文件的XML文档时,它将以此形式呈现(其中-06:00表示时区):
2000-01-18-06:00
如何配置CXF不渲染时区?
<jaxws:bindings wsdlLocation="YOUR_WSDL_LOCATION" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='THE_NAMESPACE_OF_YOUR_SCHEMA']"> <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <jxb:javaType name="java.util.Date" xmlType="xs:date" parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDate" printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDate"/> </jxb:globalBindings> </jaxws:bindings> </jaxws:bindings>
您可以参考 http://cxf.apache.org/docs/wsdl-to-java.html 部分“如何将xsd:dateTime映射到java.util.Date?”更多细节.
http://stackoverflow.com/questions/6143224/how-do-i-represent-dates-without-the-timezone-using-apache-cxf