java - JAXB 和包含泛型的集合

标签 java generics jaxb

我们有下面的 JAXB/Java 代码。在我们更改 List<JQGridTO> rows 之前,这一切都很好至 List<? extends JQGridTO> rows .

当我们进行更改时,出现此错误:

Constructor threw exception; nested exception is com.sun. xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions Property rows appears in @XmlType.propOrder, but no such property exists. Maybe you meant records? this problem is related to the following location: at com.me.ui.service.JQGridJsonRoot

为什么会出现这个错误?您不能像我们一样使用泛型(即:指定 ? extends XXX )吗?

@XmlRootElement
@XmlType(name = "", propOrder = {
        "records",
        "page",
        "total",
        "rows"
})
public class JQGridJsonRoot {
    int total; //total pages for the query
    int page; //current page of the query
    int records; //total number of records for the query
    List<? extends JQGridTO> rows
    ...

最佳答案

看看这篇 SO 帖子。我想它有你需要的:JAXB Marshalling and Generics

关于java - JAXB 和包含泛型的集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4136240/

相关文章:

java - 泛型和流 : How to make this into a `StreamTuple::new` statement?

xml - 在模块路径或类路径上未找到 JAXB-API 的 javax.xml.bind.JAXBException 实现

java - 如何避免或重命名 jaxb 中的键和条目标签?

swift - 数组中具有关联类型的协议(protocol) - 替代解决方案

java - 在泛型类中使用枚举(作为类型)并循环遍历其元素

java - 如何解析可能有或没有命名空间的 XML 内容?

Java 随机数生成器

java - Android YouTube 数据 API - Android key 设置不正确

java - 带 Tapestry 的电子邮件的正则表达式

java - 使用 Apache Wicket 将焦点放在组件上?