I wrote class A with the xmlns attribute.
@XmlRootElement(name = "A") @XmlAccessorType(XmlAccessType.FIELD) public class A { @XmlAttribute(name = "xmlns") private String xmlnsAttr; public String getXmlnsAttr() { return xmlnsAttr; } public void setXmlnsAttr(String xmlnsAttr) { this.xmlnsAttr = xmlnsAttr; } } If you change the name of this attribute (say, to 'a'), then everything works fine. But I need an attribute with the name 'xmlns'. When using it, I get an error
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.w3.org/2000/09/xmldsig#", local:"A"). Expected elements are <{}A> Test code:
@Test public void test() throws Exception { StringReader reader = new StringReader("<A xmlns=\"http://www.w3.org/2000/09/xmldsig#\"></A>"); JAXBContext jc = JAXBContext.newInstance(A.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); A a = (A) unmarshaller.unmarshal(reader); assert a.getXmlnsAttr() != null; } What can be fixed? I looked in the direction of XmlScheme , but it helped me a little: at best, I added postfix.