jaxb - 如何删除 @XmlElementRefs 并用 java 属性替换它们
问题描述
我有以下课程
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"content"
})
@XmlRootElement(name = "SegmentFilter")
public class SegmentFilter {
@XmlElementRefs({
@XmlElementRef(name = "StopRange", type = JAXBElement.class),
@XmlElementRef(name = "OverlapRange", type = JAXBElement.class),
@XmlElementRef(name = "DateRange", type = JAXBElement.class),
@XmlElementRef(name = "DurationRange", type = JAXBElement.class),
@XmlElementRef(name = "EmployeeSelector", type = JAXBElement.class),
@XmlElementRef(name = "SegmentCode", type = JAXBElement.class),
@XmlElementRef(name = "StartRange", type = JAXBElement.class)
})
@XmlMixed
protected List<Serializable> content;
@XmlAttribute(name = "IncludeDetailSegments")
protected Boolean includeDetailSegments;
@XmlAttribute(name = "IncludeGeneralSegments")
protected Boolean includeGeneralSegments;
public List<Serializable> getContent() {
if (content == null) {
content = new ArrayList<Serializable>();
}
return this.content;
}
public boolean isIncludeDetailSegments() {
if (includeDetailSegments == null) {
return true;
} else {
return includeDetailSegments;
}
}
public void setIncludeDetailSegments(Boolean value) {
this.includeDetailSegments = value;
}
public boolean isIncludeGeneralSegments() {
if (includeGeneralSegments == null) {
return true;
} else {
return includeGeneralSegments;
}
}
public void setIncludeGeneralSegments(Boolean value) {
this.includeGeneralSegments = value;
}
}
有人可以帮我用实际的java代码替换ref,比如......
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"content"
})
@XmlRootElement(name = "SegmentFilter")
public class SegmentFilter {
public DateTimeRangeType StopRange;
public DateTimeRangeType StartRange;
//and so on with getters and setters
@XmlAttribute(name = "IncludeDetailSegments")
protected Boolean includeDetailSegments;
@XmlAttribute(name = "IncludeGeneralSegments")
protected Boolean includeGeneralSegments;
public List<Serializable> getContent() {
if (content == null) {
content = new ArrayList<Serializable>();
}
return this.content;
}
public boolean isIncludeDetailSegments() {
if (includeDetailSegments == null) {
return true;
} else {
return includeDetailSegments;
}
}
public void setIncludeDetailSegments(Boolean value) {
this.includeDetailSegments = value;
}
public boolean isIncludeGeneralSegments() {
if (includeGeneralSegments == null) {
return true;
} else {
return includeGeneralSegments;
}
}
public void setIncludeGeneralSegments(Boolean value) {
this.includeGeneralSegments = value;
}
}
如果我使用复杂对象的实际 xsd 删除类型,我能够做到这一点,例如 DateTimeRangeType 在这种情况下,我使用 eclipse 生成 jaxb 类,这是下面的 xsd,在早期没有类型且所有元素的情况下在主父类中定义它能够获得 xsd 格式,但在 type 指向复杂类型的 xsd 的这种情况下似乎不起作用
<xs:element name="SegmentFilter">
<xs:annotation>
<xs:documentation>
SegmentFilter is a root-level element used
in a SegmentFilter request.
</xs:documentation>
</xs:annotation>
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="EmployeeSelector"
type="EmployeeSelectorType" minOccurs="0" />
<xs:element name="DateRange"
type="DateRangeType"/>
<xs:element name="DurationRange"
type="FromToTimeRangeType"/>
<xs:element name="SegmentCode"
type="EmptySKType"/>
<xs:element name="OverlapRange"
type="DateTimeRangeType"/>
<xs:element name="StartRange"
type="DateTimeRangeType"/>
<xs:element name="StopRange"
type="DateTimeRangeType"/>
</xs:sequence>
<xs:attribute name="IncludeDetailSegments"
default="true" type="xs:boolean"/>
<xs:attribute name="IncludeGeneralSegments"
default="true" type="xs:boolean"/>
</xs:complexType>
</xs:element>
解决方案
推荐阅读
- jboss6.x - 如何记录或监视放置在队列中的 JMS 消息?
- python-3.x - 更新 Teradata 版本时 Python 代码停止工作
- c# - Asp.Net Core Web Api 中的 Azure AD 挑战 + 我自己的 JWT 承载
- python - 如何在匹配多个不同列的同时比较 Pandas 中的列?
- google-cloud-dataflow - 使用 SSL 的 Google Cloud Postgresql 的 Java 连接字符串 - 数据流
- r - 将 R data.table 插入/更新到 PostgreSQL 表中
- qt - 如何从数据库中的坐标向地图添加项目?
- elasticsearch - 在 Elasticsearch 中为每个子查询指定大小
- ansible - Ansible yum 模块看不到带有选项 installroot 的存储库
- c# - 跨负载均衡应用程序的并发和锁定