java-JAXB生成的方法未使用泛型
作者:互联网
我有一个JAXB模式,其中一个类包含另一个类的列表.该架构如下所示.
但是,每当我从该模式创建Java类时,该方法就不会使用泛型,因此我必须像Java 5之前一样使用强制类型转换.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:common="glodas.research">
<xs:import namespace="glodas.research" schemaLocation="../common.xsd" />
<!-- Dashboard Level -->
<xs:complexType name="DashboardStatType">
<xs:complexContent>
<xs:extension base="common:IndustryRegionType">
<xs:sequence>
<xs:element name="ModuleStat" type="ModuleStatType"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="BitsCount" type="BitsCount"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="AgeLimitViolation" type="AgeLimitViolation"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ModuleViolation" type="ModuleViolation"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="BrCode" type="xs:string" />
<xs:attribute name="RegionDescription" type="xs:string" />
<xs:attribute name="AverageAgeOfBits" type="xs:int" use="required"/>
<xs:attribute name="NewestBitDate" type="xs:date" use="required"/>
<xs:attribute name="OldestBitDate" type="xs:date" use="required"/>
<xs:attribute name="ChapterCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
<xs:attribute name="UnpublishedCount" type="xs:int" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- Module Level -->
<xs:complexType name="ModuleStatType">
<xs:sequence>
<xs:element name="ChapterStat" type="ChapterStatType"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="BitsCount" type="BitsCount"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="AgeLimitViolation" type="AgeLimitViolation"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="ChapterCountViolation" type="ChapterCountViolation"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="ModuleDescription" type="xs:string" />
<xs:attribute name="ModuleNumber" type="xs:int" use="required" />
<xs:attribute name="AverageAgeOfBits" type="xs:int" use="required"/>
<xs:attribute name="NewestBitDate" type="xs:date" use="required"/>
<xs:attribute name="OldestBitDate" type="xs:date" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
<xs:attribute name="UnpublishedCount" type="xs:int" use="required"/>
</xs:complexType>
<!-- Chapter Level -->
<xs:complexType name="ChapterStatType">
<xs:sequence>
<xs:element name="BitStat" type="BitStatType" minOccurs="0"
maxOccurs="unbounded" />
<xs:element name="BitsCount" type="BitsCount"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="AgeLimitViolation" type="AgeLimitViolation"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="ChapterId" type="xs:int" use="required"/>
<xs:attribute name="ChapterTitle" type="xs:string" use="required"/>
<xs:attribute name="AverageAgeOfBits" type="xs:int" use="required"/>
<xs:attribute name="NewestBitDate" type="xs:date" use="required"/>
<xs:attribute name="OldestBitDate" type="xs:date" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
</xs:complexType>
<!-- Bit Level -->
<xs:complexType name="BitStatType">
<xs:sequence>
<xs:element name="BitStat" type="BitStatType" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="BitAge" type="BitAge" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="WiId" type="xs:int" use="required"/>
<xs:attribute name="Title" type="xs:string" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
<xs:attribute name="LastPublishedDate" type="xs:date" use="required"/>
</xs:complexType>
<xs:complexType name="ValidationMessage">
<xs:attribute name="Text" type="xs:string" use="required"/>
<xs:attribute name="Severity" type="xs:int" use="optional"/>
</xs:complexType>
<xs:complexType name="BitAge">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Age" type="xs:int" use="required" />
</xs:complexType>
<xs:complexType name="BitsCount">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required" />
</xs:complexType>
<xs:complexType name="AgeLimitViolation">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required" />
</xs:complexType>
<xs:complexType name="ChapterCountViolation">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required" />
</xs:complexType>
<xs:complexType name="ModuleViolation">
<xs:sequence>
<xs:element name="ValidationMessage" type="ValidationMessage"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required" />
</xs:complexType>
<xs:element name="GetDashboardMonitorResponse">
<xs:annotation>
<xs:documentation>Response for DashboardMonitor.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element type="DashboardStatType" name="DashboardStat" minOccurs="1"
maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
…方法是这样生成的
java.util.List getBitAge();
我希望这样生成java方法
java.util.List<BitAge> getBitAge();
解决方法:
您能否提供有关XML模式的更多详细信息?我试图重现以下问题
nov30.xsd
我对您提供的XML模式进行了更改,因为我没有common.xsd的源代码:
<!--xs:import namespace="glodas.research" schemaLocation="../common.xsd" / -->
<!-- Dashboard Level -->
<xs:complexType name="DashboardStatType">
<!--xs:complexContent>
<xs:extension base="common:IndustryRegionType"-->
<xs:sequence>
<xs:element name="ModuleStat" type="ModuleStatType"
minOccurs="0" maxOccurs="unbounded" />
<xs:element name="BitsCount" type="BitsCount"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="AgeLimitViolation" type="AgeLimitViolation"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ModuleViolation" type="ModuleViolation"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="BrCode" type="xs:string" />
<xs:attribute name="RegionDescription" type="xs:string" />
<xs:attribute name="AverageAgeOfBits" type="xs:int" use="required"/>
<xs:attribute name="NewestBitDate" type="xs:date" use="required"/>
<xs:attribute name="OldestBitDate" type="xs:date" use="required"/>
<xs:attribute name="ChapterCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerRulesCount" type="xs:int" use="required"/>
<xs:attribute name="TriggerEventsCount" type="xs:int" use="required"/>
<xs:attribute name="UnpublishedCount" type="xs:int" use="required"/>
<!-- /xs:extension>
</xs:complexContent -->
</xs:complexType>
XJC电话
xjc -d out nov30.xsd
BitStatType
结果列表属性仍按预期使用泛型:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2011.11.30 at 11:38:04 AM EST
//
package generated;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;
/**
* <p>Java class for BitStatType complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="BitStatType">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="BitStat" type="{}BitStatType" maxOccurs="unbounded" minOccurs="0"/>
* <element name="BitAge" type="{}BitAge" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* <attribute name="WiId" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
* <attribute name="Title" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="TriggerRulesCount" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
* <attribute name="TriggerEventsCount" use="required" type="{http://www.w3.org/2001/XMLSchema}int" />
* <attribute name="LastPublishedDate" use="required" type="{http://www.w3.org/2001/XMLSchema}date" />
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BitStatType", propOrder = {
"bitStat",
"bitAge"
})
public class BitStatType {
@XmlElement(name = "BitStat")
protected List<BitStatType> bitStat;
@XmlElement(name = "BitAge")
protected List<BitAge> bitAge;
@XmlAttribute(name = "WiId", required = true)
protected int wiId;
@XmlAttribute(name = "Title", required = true)
protected String title;
@XmlAttribute(name = "TriggerRulesCount", required = true)
protected int triggerRulesCount;
@XmlAttribute(name = "TriggerEventsCount", required = true)
protected int triggerEventsCount;
@XmlAttribute(name = "LastPublishedDate", required = true)
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar lastPublishedDate;
/**
* Gets the value of the bitStat 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 bitStat property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getBitStat().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link BitStatType }
*
*
*/
public List<BitStatType> getBitStat() {
if (bitStat == null) {
bitStat = new ArrayList<BitStatType>();
}
return this.bitStat;
}
/**
* Gets the value of the bitAge 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 bitAge property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getBitAge().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link BitAge }
*
*
*/
public List<BitAge> getBitAge() {
if (bitAge == null) {
bitAge = new ArrayList<BitAge>();
}
return this.bitAge;
}
/**
* Gets the value of the wiId property.
*
*/
public int getWiId() {
return wiId;
}
/**
* Sets the value of the wiId property.
*
*/
public void setWiId(int value) {
this.wiId = value;
}
/**
* Gets the value of the title property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTitle() {
return title;
}
/**
* Sets the value of the title property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTitle(String value) {
this.title = value;
}
/**
* Gets the value of the triggerRulesCount property.
*
*/
public int getTriggerRulesCount() {
return triggerRulesCount;
}
/**
* Sets the value of the triggerRulesCount property.
*
*/
public void setTriggerRulesCount(int value) {
this.triggerRulesCount = value;
}
/**
* Gets the value of the triggerEventsCount property.
*
*/
public int getTriggerEventsCount() {
return triggerEventsCount;
}
/**
* Sets the value of the triggerEventsCount property.
*
*/
public void setTriggerEventsCount(int value) {
this.triggerEventsCount = value;
}
/**
* Gets the value of the lastPublishedDate property.
*
* @return
* possible object is
* {@link XMLGregorianCalendar }
*
*/
public XMLGregorianCalendar getLastPublishedDate() {
return lastPublishedDate;
}
/**
* Sets the value of the lastPublishedDate property.
*
* @param value
* allowed object is
* {@link XMLGregorianCalendar }
*
*/
public void setLastPublishedDate(XMLGregorianCalendar value) {
this.lastPublishedDate = value;
}
}
标签:jaxb,xsd,java 来源: https://codeday.me/bug/20191202/2085333.html