spring 每个名称空间的JAXB不同数据类型解析

brgchamk  于 2022-10-31  发布在  Spring
关注(0)|答案(1)|浏览(210)

我已经得到了如下的JAXB绑定配置文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               version="2.1">
    <jaxb:globalBindings generateElementProperty="false">
        <jaxb:javaType name="java.util.Date" xmlType="xs:dateTime"
                       parseMethod="com.utils.EmptyDateTimeAdapter.parseDateTime"
                       printMethod="com.utils.EmptyDateTimeAdapter.printDateTimeWithZone"/>
        <xjc:serializable uid="-1"/>
    </jaxb:globalBindings>
</jaxb:bindings>

在上面的xml中,我声明了每个wsdl dateTime元素都将被这些方法解析。
我的问题是:如何更改此JAXB配置文件,以便为每个包名或每个wsdl的元素类型指定多个解析方法?

5jvtdoz2

5jvtdoz21#

<jaxws:bindings wsdlLocation="SampleService.wsdl"          
    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='http://example.com/service/SampleService/']">      
        <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.parseDateTime"
                      printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDateTime"/>                   
    </jxb:globalBindings>  
    </jaxws:bindings>
</jaxws:bindings>

参考文献:JBoss Community Archive (Read Only)
JAXB bindings and xs:date to java.util.Date
Custom Jax-b bindings for xs:date to JAVA 8 java.time.LocalDate using Adapter

相关问题