Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 扩展抽象泛型类的解组类_Java_Generics_Jaxb_Unmarshalling - Fatal编程技术网

Java 扩展抽象泛型类的解组类

Java 扩展抽象泛型类的解组类,java,generics,jaxb,unmarshalling,Java,Generics,Jaxb,Unmarshalling,我的类层次结构: @XmlAccessorType(XmlAccessType.FIELD) public abstract class GenericItem { @XmlElement(name = "Id", required = true) private String itemId; ////other fields } @XmlAccessorType(XmlAccessType.FIELD) public class Item extends Gene

我的类层次结构:

@XmlAccessorType(XmlAccessType.FIELD)
public abstract class GenericItem  {
    @XmlElement(name = "Id", required = true)
    private String itemId;
    ////other fields
} 

@XmlAccessorType(XmlAccessType.FIELD)
public class Item extends GenericItem {
   @XmlElement(name = "AreaType", required = true)
   private String areaType;
   ///other fields
}


@XmlAccessorType(XmlAccessType.FIELD)
public abstract class GenericData<T extends GenericItem>{

  @XmlElement(name = "Item")
  private List<T> itemList;

  public List<T> getItemList() {
    return itemList;
  }

  public void setItemList(List<T> itemList) {
    this.itemList = itemList;
  }
  ////other fields
}


 @XmlRootElement(name = "Data")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class Data extends GenericData<Item> {
   ////other fields
 }  
@xmlacessortype(xmlacesstype.FIELD)
公共抽象类泛型项{
@xmlement(name=“Id”,required=true)
私有字符串itemId;
////其他领域
} 
@XmlAccessorType(XmlAccessType.FIELD)
公共类项扩展了GenericItem{
@XmlElement(name=“AreaType”,必需=true)
私有字符串类型;
///其他领域
}
@XmlAccessorType(XmlAccessType.FIELD)
公共抽象类GenericData{
@xmlement(name=“Item”)
私人清单项目清单;
公共列表getItemList(){
返回项目列表;
}
公共无效集合项目列表(列表项目列表){
this.itemList=itemList;
}
////其他领域
}
@XmlRootElement(name=“Data”)
@XmlAccessorType(XmlAccessType.FIELD)
公共类数据扩展了GenericData{
////其他领域
}  
当我试图取消Marhal XML文档时

 <Data>
   <Item/>
   <Item/>
 </Date>

我有错误javax.xml.bind.UnmarshalException-带有链接异常: [com.sun.istack.SAXParseException2;无法创建GenericItem的实例]

JAXBContext jc=JAXBContext.newInstance(Data.class,GenericData.class,Item.class,generitem.class);
Unmarshaller Unmarshaller=jc.createUnmarshaller();
--此处出错-->JAXBElement jb=unmarshaller.unmarshal(xmlStreamReader,Data.class);

请,我需要帮助:(

作为一种解决方法,删除抽象关键字并尝试使用泛型类

list of java classes to be recognized by the new JAXBContext. 
这是文档中对classesToBeBound参数的说明,说明它应该能够创建一个新对象来识别参数。对于抽象类,这是不可能的


尝试使用
@MappedSuperclass
@xmlseea
的组合。用它们注释基类并使它们抽象。

删除类GenericItem和GenericData的抽象,然后重试。
list of java classes to be recognized by the new JAXBContext.