我遇到一个问题,解组包含xsd:anyType(ur-type)对象的数据,例如:
<xsd:element name="Options" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Key" minOccurs="0"/>
<xsd:element name="Next" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
JAXB2为上面的元素创建以下Java类;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"key",
"next"
})
public static class Options {
@XmlElement(name = "Key")
protected Object key;
@XmlElement(name = "Next")
protected Object next;
/**
* Gets the value of the key property.
*
* @return
* possible object is
* {@link Object }
*
*/
public Object getKey() {
return key;
}
/**
* Sets the value of the key property.
*
* @param value
* allowed object is
* {@link Object }
*
*/
public void setKey(Object value) {
this.key = value;
}
/**
* Gets the value of the next property.
*
* @return
* possible object is
* {@link Object }
*
*/
public Object getNext() {
return next;
}
/**
* Sets the value of the next property.
*
* @param value
* allowed object is
* {@link Object }
*
*/
public void setNext(Object value) {
this.next = value;
}
}
编组工作正常,但在解组时会引发以下异常;
org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
at org.apache.xerces.dom.CoreDocumentImpl.checkNamespaceWF(Unknown Source)
at org.apache.xerces.dom.ElementNSImpl.setName(Unknown Source)
at org.apache.xerces.dom.ElementNSImpl.<init>(Unknown Source)
at org.apache.xerces.dom.CoreDocumentImpl.createElementNS(Unknown Source)
at org.apache.xml.utils.DOMBuilder.startElement(DOMBuilder.java:322)
at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1072)
at com.sun.xml.bind.v2.runtime.unmarshaller.DomLoader.startElement(DomLoader.java:118)
at com.sun.xml.bind.v2.runtime.unmarshaller.XsiTypeLoader.startElement(XsiTypeLoader.java:73)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:455)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:433)
at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:71)
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:240)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:277)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:246)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:277)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:246)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:277)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:246)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:123)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:314)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:297)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:107)
at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:581)
at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:568)
...
我正在使用;
JDK 1.6.0_19
spring-oxm-3.0.5.RELEASE.jar
jaxb-impl-2.1.7.jar
jaxb-api-2.1.jar
com.springsource.org.apache.xalan-2.7.0.jar
com.springsource.org.apache.xerces-2.8.1.jar
谢谢,
Henry Kim