如何使用Apache CXF表示没有时区的日期? [英] How do I represent dates without the timezone using Apache CXF?

查看:103
本文介绍了如何使用Apache CXF表示没有时区的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WSDL,它指定一个元素的类型为xs:date。

I have a WSDL that specifies an element's type to be xs:date.

当我使用Apache CXF生成Java类时,它将变量呈现为javax.xml.datatype.XMLGregorianCalendar(到目前为止都很好)。

When I use Apache CXF to generate the Java classes, it renders the variable as an javax.xml.datatype.XMLGregorianCalendar (all good so far).

当CXF呈现包含此文档的XML文档时,它会以这种形式呈现它(其中-06:00)表示时区):

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

2000-01-18-06:00

如何配置CXF不渲染时区?

How can I configure CXF not to render the timezone?

推荐答案

默认情况下wsdl的 xsd:date 被映射到 XMLGregorianCalendar 。如果这不是您想要的,那么如果您使用CXF的 wsdl到java 工具,那么您可以提供一个绑定文件来覆盖此默认映射:

By default wsdl's xsd:date gets mapped to XMLGregorianCalendar. If this is not what you want then if you are using CXF's wsdl to java tool then you can provide a binding file to override this default mapping:

<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。日期?了解更多详情。

You can refer to http://cxf.apache.org/docs/wsdl-to-java.html section "How to map xsd:dateTime to java.util.Date?" for more details.

这篇关于如何使用Apache CXF表示没有时区的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆