为什么JAXB generateElementProperty = false没有达到预期的效果? [英] Why is JAXB generateElementProperty=false not having the desired effect?
问题描述
我正在使用以下绑定文件运行wsimport任务:
I'm running a wsimport task with the following bindings file:
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<jaxb:bindings>
<jaxb:globalBindings generateElementProperty="false" typesafeEnumMaxMembers="2000" />
</jaxb:bindings>
</jaxb:bindings>
然而,这导致类 JAXBElement< String>
而不是 String
,如 getUserSummaryOrTypeOrLogLevel()
所示
However, this is resulting in classes with JAXBElement<String>
instead of String
as shown in the getUserSummaryOrTypeOrLogLevel()
below
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ConfigSLMAction", propOrder = {
"userSummaryOrTypeOrLogLevel"
})
public class ConfigSLMAction
extends ConfigConfigBase
{
@XmlElementRefs({
@XmlElementRef(name = "UserSummary", type = JAXBElement.class, required = false),
@XmlElementRef(name = "LogLevel", type = JAXBElement.class, required = false),
@XmlElementRef(name = "Type", type = JAXBElement.class, required = false)
})
protected List<JAXBElement<String>> userSummaryOrTypeOrLogLevel;
@XmlAttribute(name = "name")
protected String name;
@XmlAttribute(name = "local")
protected Boolean local;
@XmlAttribute(name = "intrinsic")
protected Boolean intrinsic;
@XmlAttribute(name = "read-only")
protected Boolean readOnly;
@XmlAttribute(name = "external")
protected Boolean external;
/**
* Gets the value of the userSummaryOrTypeOrLogLevel property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the userSummaryOrTypeOrLogLevel property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getUserSummaryOrTypeOrLogLevel().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
*
*
*/
public List<JAXBElement<String>> getUserSummaryOrTypeOrLogLevel() {
if (userSummaryOrTypeOrLogLevel == null) {
userSummaryOrTypeOrLogLevel = new ArrayList<JAXBElement<String>>();
}
return this.userSummaryOrTypeOrLogLevel;
}
...
...
...
}
xsd文件中生成此类的条目如下:
The entry in the xsd file that this class is being generated from is below:
<xsd:complexType name="ConfigSLMAction">
<xsd:complexContent>
<xsd:extension base="tns:ConfigConfigBase">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="UserSummary" minOccurs="0" maxOccurs="1">
<xsd:simpleType>
<xsd:union memberTypes="tns:dmString tns:dmEmptyElement" />
</xsd:simpleType>
</xsd:element>
<xsd:element name="Type" minOccurs="1" maxOccurs="1">
<xsd:simpleType>
<xsd:union memberTypes="tns:dmSLMActionType tns:dmEmptyElement" />
</xsd:simpleType>
</xsd:element>
<xsd:element name="LogLevel" minOccurs="0" maxOccurs="1">
<xsd:simpleType>
<xsd:union memberTypes="tns:dmLogLevel tns:dmEmptyElement" />
</xsd:simpleType>
</xsd:element>
</xsd:choice>
<xsd:attributeGroup ref="tns:ConfigAttributes" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
这是我的pom文件中的Maven插件
Here's the Maven plugin from my pom file
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>wsimport-from-jdk</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlFiles>
<wsdlFile>${basedir}/src/main/resources/wsdl/xml-mgmt.wsdl</wsdlFile>
</wsdlFiles>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl/bindings.xml</bindingFile>
</bindingFiles>
<keep>true</keep>
<verbose>true</verbose>
<extension>true</extension>
<vmArgs>
<vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
</configuration>
</plugin>
有人能说清楚为什么会这样吗?
我希望 String
代替 JAXBElement< String>
以及我在SO上找到的任何内容和其他地方建议 generateElementProperty = false
工作但不是。
Can anyone shed some light on why this is happening?
I want String
to be used instead of JAXBElement<String>
and anything I've found on SO and elsewhere suggests that generateElementProperty=false
work but it isn't.
推荐答案
如果 xsd:choice
其中 foo
或 bar
元素可以发生,它们是相同的类型。
一个简单的String不足以标记应该编组哪个元素。
The JAXBElement
is mandatory if there is a xsd:choice
where either foo
or bar
elements can occur and they are the same type.
A simple String isn't enough to mark which element should be marshalled.
JAXBElement
是必需的如果有元素 nillable =true
和 minOccurs =0
或者如果有两个全局元素同名的 xsd:complexType
。
JAXBElement
is required also if there are element nillable="true"
and minOccurs="0"
or if there are two global elements with the same named xsd:complexType
.
这篇关于为什么JAXB generateElementProperty = false没有达到预期的效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!