为什么JAXB generateElementProperty = false没有达到预期的效果?
我正在使用以下绑定文件运行wsimport任务:
但是,这会导致使用JAXBElement
而不是String
,如下面的getUserSummaryOrTypeOrLogLevel()
所示
@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> 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. * *
* 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
set
method for the userSummaryOrTypeOrLogLevel property. * ** For example, to add a new item, do as follows: *
* getUserSummaryOrTypeOrLogLevel().add(newItem); ** * *
* Objects of the following type(s) are allowed in the list * {@link JAXBElement }{@code } * {@link JAXBElement }{@code } * {@link JAXBElement }{@code } * * */ public List<JAXBElement> getUserSummaryOrTypeOrLogLevel() { if (userSummaryOrTypeOrLogLevel == null) { userSummaryOrTypeOrLogLevel = new ArrayList<JAXBElement>(); } return this.userSummaryOrTypeOrLogLevel; } ... ... ... }
生成此类的xsd文件中的条目如下:
这是我的pom文件中的Maven插件
org.jvnet.jax-ws-commons jaxws-maven-plugin 2.3 wsimport-from-jdk generate-sources wsimport ${basedir}/src/main/resources/wsdl/xml-mgmt.wsdl ${basedir}/src/main/resources/wsdl/bindings.xml true true true -Djavax.xml.accessExternalDTD=all -Djavax.xml.accessExternalSchema=all
任何人都可以解释为什么会这样吗? 我希望使用
String
代替JAXBElement
,我在SO和其他地方找到的任何东西都表明generateElementProperty=false
工作,但事实并非如此。如果存在
xsd:choice
,则JAXBElement
是必需的,其中foo
或bar
元素可以出现且它们是相同的类型。 一个简单的String不足以标记应该编组哪个元素。如果存在元素
nillable="true"
和minOccurs="0"
或者如果存在两个具有相同名称xsd:complexType
全局元素,则还需要JAXBElement
。你能尝试另一个插件来确保JAXB中有错误吗? 在我们的项目中,我们使用:
org.apache.cxf cxf-codegen-plugin generate-sources-ais generate-sources ${basedir}/src/main/resources/wsdl/binding/bindings.xml ${project.build.directory}/generated-sources/cxf ${basedir}/src/main/resources/wsdl **/*.wsdl wsdl2java 它按预期工作
更新:
你是正确的插件是好的。 这是因为选择元素。 可能与此重复