我的xsd有两个用minouucrs = 0和nillable = true定义的字段。当我为此生成Java对象时,它生成JAXBElement而不是普通字符串。有任何解决方法可以避免JAXBElement。
JAXBElement<String> userId,
JAXBElement<String> userType.
**testSchema.xsd**
<xs:complexType name="testSchema">
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:int" />
<xs:element minOccurs="0" name="age" type="xs:int" />
<xs:element minOccurs="0" name="userId" nillable="true"
type="xs:string" />
<xs:element minOccurs="0" name="usertype" nillable="true"
type="xs:string" />
</xs:sequence>
</xs:complexType>
Why it's not creating normal XMLElement instaed of creating XMLElementRef?
I am using below dependency and plugin.
pom Dependencies
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.schema</groupId>
<artifactId>XmlSchema</artifactId>
<version>1.4.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.source.version}</source>
<target>${java.target.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>schema1-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/schema/testschema</schemaDirectory>
<generateDirectory>src/main/java</generateDirectory>
<schemaIncludes>
<include>**/*.wsdl</include>
<include>*.wsdl</include>
</schemaIncludes>
<generateDirectory>src/main/java</generateDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我也在src / main / resources
下定义了bindings.xjb<jaxb:bindings version="2.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="/schema/testschema/*.xsd"
node="/xs:schema">
<jaxb:globalBindings generateElementProperty="false"/>
</jaxb:bindings>
为什么它为这两个字段生成JAXBElement而不是普通的String。