Java 编译时强制使用联合成员类型的Jaxb首选项

Java 编译时强制使用联合成员类型的Jaxb首选项,java,xml,jaxb,xjc,Java,Xml,Jaxb,Xjc,我正在使用xjc编译一个XSD,其中包括以下类型: <xs:simpleType name="CPT-DateTime"> <xs:annotation> <xs:appinfo>Can be specified as a integer number or as xs:dateTime</xs:appinfo> </xs:annotation> <xs:union memberTypes=

我正在使用xjc编译一个XSD,其中包括以下类型:

<xs:simpleType name="CPT-DateTime">
    <xs:annotation>
        <xs:appinfo>Can be specified as a integer number or as xs:dateTime</xs:appinfo>
    </xs:annotation>
    <xs:union memberTypes="xs:unsignedLong xs:dateTime"/>
</xs:simpleType>

可以指定为整数或xs:dateTime
使用此类型的结果类将使用此元素集作为字符串进行编译,而我更希望它们使用XMLGregorianCalendar

有没有一种方法可以强制xjc在字符串上选择xs:dateTime成员类型?我已经看到了如何为联合而不是联合做这件事。

我相信,对于任意简单类型,什么才是真正有效的。假设
tns
是架构中targen命名空间的声明前缀,请尝试以下映射:

<globalBindings>
    <javaType name="javax.xml.datatype.XMLGregorianCalendar" xmlType="tns:CPT-DateTime" .../>
</globalBindings>

然而,我不是100%肯定

同时检查。

此处有类似问题


。我正在添加一个小型适配器。

该解决方案得益于denishaskin的最终实现:

<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings jxb:version="2.1" xmlns:jxb="{NS1-n}" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<jxb:bindings node="/xs:schema" schemaLocation="../{SCHEMA}.xsd">
<jxb:globalBindings>
<jxb:javaType name="org.joda.time.DateTime" xmlType="xs:dateTime"/>
<jxb:javaType name="org.joda.time.DateTime" xmlType="tns:CPT-DateTime"/>
<jxb:javaType name="org.joda.time.LocalDate" xmlType="tns:CPT-Date"/>
<jxb:javaType name="org.joda.time.LocalTime" xmlType="tns:CPT-Time"/>
</jxb:globalBindings>
</jxb:bindings>