我将 JAXB 与 CXF Web 服务一起使用。当我通过时:
<?xml version="1.0" ?><ns2:Optionen xmlns:ns2="http://test.at/ezustellung/global/20090501#">
<ns2:PdfAKonvertierung>true</ns2:PdfAKonvertierung><ns2:SignaturTyp>Adobe</ns2:SignaturTyp>
</ns2:Optionen>
对于解组器,属性 pdfAKonvertierung 和 signaturTyp 在我的对象中都是空的。但如果我通过:
<?xml version="1.0" ?><ns2:Optionen xmlns:ns2="http://test.at/ezustellung/global/20090501#">
<PdfAKonvertierung>true</PdfAKonvertierung><SignaturTyp>Adobe</SignaturTyp>
</ns2:Optionen>
这是无效的,根据 CXF 验证器和维基百科(翻译,没有找到英文):
具有命名空间前缀的元素的子元素不会自动具有相同的命名空间,它们也必须以命名空间为前缀。
相应地设置属性。有人能发现我的代码中的错误吗,或者我在 Java 1.6 的 JAXB 实现中发现了错误吗?
作为参考,这是我的代码:
 public class JaxbTests {
  @Test
  public void testOptionen() throws JAXBException, SAXException, IOException {
   JAXBContext context = JAXBContext.newInstance(Optionen.class);
   Unmarshaller unmarshaller = context.createUnmarshaller();
   ByteArrayInputStream is = new ByteArrayInputStream(
     // Does not work
     ("<?xml version=\"1.0\" ?><ns2:Optionen xmlns:ns2=\"http://test.at/ezustellung/global/20090501#\">" +
     "<ns2:PdfAKonvertierung>true</ns2:PdfAKonvertierung><ns2:SignaturTyp>Adobe</ns2:SignaturTyp>" +
     "</ns2:Optionen>").getBytes());
     // Works
 //    ("<?xml version=\"1.0\" ?><ns2:Optionen …