在我的maven项目中,我希望所有的datetime条目都应该以java.util.date而不是XMLGregorianCalendar的形式生成。您可能知道,默认情况下会生成XMLGregorianCalendar。
我们可以以提供这里的项目为例。
在CustomersOrders.xsd中,您可以看到attriute ShippedDate是dateTime类型的。
<xs:attribute name='ShippedDate' type='xs:dateTime' />要将其数据类型转换为java.util.date,我将遵循文档这里中提供的方法。例如,通过使用外部绑定文件,例如:
Customer.xjb
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<globalBindings>
<javaType name="java.util.date" xmlType="xs:datetime"
parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
printMethod="javax.xml.bind.DatatypeConverter.printDate"
/>
</globalBindings>
</bindings>然后我将Customer.xjb文件映射到pom.xml中,如下所示:
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- the package for the generated java classes -->
<generatePackage>com.dimitrisli.jaxb.producedClasses</generatePackage>
<!-- If the following not specified all xsd in resources are included -->
<schemaIncludes>
<include>sampleJaxb/CustomersOrders.xsd</include>
</schemaIncludes>
<!-- if you don't want old output -->
<removeOldOutput>true</removeOldOutput>
<!-- if you want verbosity -->
<!-- verbose>true</verbose -->
<xjbSources>
<xjbSource>sampleJaxb/Customers.xjb</xjbSource>
</xjbSources>
</configuration>
</execution>
</executions>但是,当我执行mvn clean install时,我仍然无法看到ShippedDate中的任何不同之处,它仍然是作为XMLGregorianCalendar生成的。
请给我建议一下我遗漏了什么。
谢谢
发布于 2017-03-29 16:36:51
org.jvnet.jaxb2.maven2:maven-jaxb2-plugin,那么您应该使用bindingIncludes而不是xjbSources (用于org.codehaus.mojo:jaxb2-maven-plugin)。
sampleJaxb/Customers.xjb `java.util.Date实现一个自定义适配器,就像在本教程中看到的那样,或者转换为java.util.Calendar希望能帮上忙!
https://stackoverflow.com/questions/43073978
复制相似问题