- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从 XSD 文件生成带有 JAXB 的 Java 类。
问题是,我总是得到一些像这样的类(删除了命名空间):
public static class Action {
@XmlElementRefs({
@XmlElementRef(name = "ReportStateCanceled", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "ReportDate", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "ReportStatePreliminary", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "DocumentID", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "ReportStateNotValidated", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "CaseNo", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "PatientID", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "DocumentKey", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "ReportTime", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "ReportHeading", namespace = "http://...", type = JAXBElement.class, required = false),
@XmlElementRef(name = "ReportStateComplete", namespace = "http://...", type = JAXBElement.class, required = false)
})
protected List<JAXBElement<?>> documentKeyOrDocumentIDOrPatientID;
@XmlAttribute(name = "name")
protected String name;
@XmlAttribute(name = "Query")
protected String query;
/**
* Gets the value of the documentKeyOrDocumentIDOrPatientID 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 documentKeyOrDocumentIDOrPatientID property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getDocumentKeyOrDocumentIDOrPatientID().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link JAXBElement }{@code <}{@link Template.Page.Actions.Action.ReportDate }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link Template.Page.Actions.Action.ReportTime }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
*
*
*/
public List<JAXBElement<?>> getDocumentKeyOrDocumentIDOrPatientID() {
if (documentKeyOrDocumentIDOrPatientID == null) {
documentKeyOrDocumentIDOrPatientID = new ArrayList<JAXBElement<?>>();
}
return this.documentKeyOrDocumentIDOrPatientID;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the query property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getQuery() {
return query;
}
/**
* Sets the value of the query property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setQuery(String value) {
this.query = value;
}
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <simpleContent>
* <extension base="<http://www.w3.org/2001/XMLSchema>string">
* <attribute name="dateFormat" type="{http://www.w3.org/2001/XMLSchema}string" />
* </extension>
* </simpleContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"value"
})
public static class ReportDate {
@XmlValue
protected String value;
@XmlAttribute(name = "dateFormat")
protected String dateFormat;
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setValue(String value) {
this.value = value;
}
/**
* Gets the value of the dateFormat property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getDateFormat() {
return dateFormat;
}
/**
* Sets the value of the dateFormat property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setDateFormat(String value) {
this.dateFormat = value;
}
}
nillable="true"
存在问题。和
minOccurs="0"
在一起,但我不在任何地方使用 nillable 。我敢肯定,这个问题与
minOccurs
相关。和
maxOccurs
.
<xs:element name="Action" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="DocumentKey" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="DocumentID" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="PatientID" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="CaseNo" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ReportHeading" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ReportDate" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string" >
<xs:attribute name="dateFormat" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="ReportTime" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string" >
<xs:attribute name="timeFormat" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="ReportStateNotValidated" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ReportStatePreliminary" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ReportStateComplete" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ReportStateCanceled" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:choice>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="Query" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc"
jaxb:version="2.0">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings generateValueClass="false" generateElementProperty="false" >
<xjc:simple />
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
</xs:schema>
最佳答案
我写了Simpify plugin正是针对这个问题。
<xs:schema ...
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
jaxb:extensionBindingPrefixes="... simplify">
<xs:complexType name="typeWithReferencesProperty">
<xs:choice maxOccurs="unbounded">
<xs:element name="a" type="someType">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="b" type="someType"/>
</xs:choice>
</xs:complexType>
@XmlElement(name = "a")
protected List<SomeType> a;
@XmlElement(name = "b")
protected List<SomeType> b;
@XmlElementRefs({
@XmlElementRef(name = "a", type = JAXBElement.class),
@XmlElementRef(name = "b", type = JAXBElement.class)
})
protected List<JAXBElement<SomeType>> aOrB;
关于JAXB 避免 JAXBElement<?>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22513736/
以下代码有效: private List custom; @XmlAnyElement public List getCustom() { if (custom == null) {
我有一个使用 Spring (v4.0.5) 的 http 服务。它的 http 端点是使用 Spring Web MVC 配置的。响应是根据模式生成的 JAXB2 注释类。响应被包装在 JAXBEl
我有一个 xsd,其中包含替换组。当我尝试使用 cxf wsdl2java JAXB 生成 Java 类时,生成 List> 而不是 List 。如何避免 JAXBElement?我尝试使用 bind
我想从 XSD 文件生成带有 JAXB 的 Java 类。 问题是,我总是得到一些像这样的类(删除了命名空间): public static class Action { @X
我在用: GSON 2.3.1 apache-cxf-3.1.1 JBoss EAP 6.4 我正在使用 wsdl2java 从 wsdl 创建 webservice 客户端。 我用以下方法生成类:
我有一个完全可用且经过测试的 REST API。我正在使用 enunciate 创建文档。 请求和响应对象是使用 jaxb 从 xsd 文件生成的。在文档中,可以识别响应对象,但我的请求正文类型是(自
我想实现一个返回 JAXBElement 的方法,下面是代码 @XmlRootElement(name = "history") @XmlAccessorType(XmlAccessType.FIEL
我有多个根元素,因此,我需要写 JAXBElement jaxbBookType = objectFactory.createBookType (bookType); JAXBElement jaxb
考虑 JAXB 生成的以下代码: public class CnpOnlineResponse { protected JAXBElement transactionResponse;
我有以下代码, JAXBContext jc = JAXBContext.newInstance(TestResults.class); Marshaller m = jc.createMarshal
当我尝试从 wsdl 文档生成客户端时,我得到的客户端似乎有很多 JAXBElement 属性,例如 protected List> nameOrLinkingNameOrFamilyName; 我使
我正在使用 NetBeans 和 Glassfish 从现有 WSDL 构建 Web 服务。NetBeans 已从给定的 WSDL 创建了所需的类。WSDL 定义了一些基本数据类型(例如 BaseTy
我定义了一个 Book 类,我想创建一个 JAXBElement 对象,该对象将包含与来自 String 对象的 XML 对应的信息。 例如,我可以有这样的东西: String code = "Har
如何编码 JAXBElement 列表? 例如,我有一个无法注释的 POJO: public class APojo { private String aString; public APojo()
我有一个方法 public Response xyz ( JAXBElement request ) { ...... } 两个不同的地方使用不同的 JAXBElement 调用它。一与 xyz(JA
您好,我想将 JAXBelement 值存储到 String 变量,请告诉我该怎么做。我有以下方法。 public JAXBElement getSessionId() { return s
我已经从我的 XML .xsd 生成了类,并且正在尝试设置一个字段 EndpointID在类(class)内MeterSessionInputRF .我遇到的问题是 setEndpointID方法只接
我正在学习 JAX-WS,并且还介绍了 JAXB。我可以用它来将 java(xml) 编码(un)编码为 xml(java)。但是这行代码的目的是什么,然后我使用 Apache CXF 生成了 WS
我有一个关于 JAXB 的简单问题。这是示例代码: //setter that has input JAXBElement b.setBIC(JAXBElement value); 如何初
我有一个名为 MYClass 的类,其代码如下所示 package com.rest; public class MyClass { private String var; publi
我是一名优秀的程序员,十分优秀!