com.sun.istack.SAXException2:class java.util.ArrayList及其任何超类在此上下文中都不为人所知

com.sun.istack.SAXException2:class java.util.ArrayList及其任何超类在此上下文中都不为人所知,java,xml,rest,jaxb,marshalling,Java,Xml,Rest,Jaxb,Marshalling,我正在用XSD验证我的请求。在我的请求中,我将我的内容设置为List 属性是一个POJO: @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "attribute", propOrder = { "name", "value" }) public class Attribute { @XmlElement(required = true) @XmlJavaTypeAdapter(CollapsedStri

我正在用XSD验证我的请求。在我的请求中,我将我的内容设置为
List

属性是一个POJO:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "attribute", propOrder = {
    "name",
    "value"
})
public class Attribute {

    @XmlElement(required = true)
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlSchemaType(name = "NCName")
    protected String name;
    @XmlElement(required = true)
    protected Object value;

    public String getName() {
        return name;
    }
    public void setName(String value) {
        this.name = value;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }
}
我的验证失败,出现异常:

Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: class java.util.ArrayList nor any of its super class is known to this context.

如何通过
列表
进行验证???

您可以为此列表创建包装

 @XmlRootElement(name="attributes")
    @XmlAccessorType(XmlAccessType.Field)
    public class{
       @XmlElement(name="attributes")
       private List<Attribute> attributes;
       public void setAttributes(List<Attribute> attributes){
           this.attributes=attributes;}
       public List<Attribute> getAttributes(){
           return this.attributes;}
    }
@XmlRootElement(name=“attributes”)
@XmlAccessorType(XmlAccessType.Field)
公共课{
@xmlement(name=“attributes”)
私有列表属性;
公共void集合属性(列表属性){
this.attributes=attributes;}
公共列表getAttributes(){
返回this.attributes;}
}
为了验证属性列表,您将属性列表传递给这个包装器,jaxb将完成其余的工作,我们需要这个类,因为解析器不接受没有用xmlRootElement和ArrayList注释的类,并且它的所有超类都没有用xmlRootElement注释
java.util.ArrayList或其任何超类在此上下文中都是未知的

您不能一次验证每个项目的列表元素吗