无法封送类型“ java.lang.String”作为元素,因为它缺少@XmlRootElement注释

时间:2019-04-07 23:40:17

标签: java xml intellij-idea marshalling unmarshalling

我正在连接到外部wsdl,并尝试来回发送一些消息。 只需尝试发送一些数据并返回确认消息,就不需要任何复杂性。 我现在的问题是我遇到了编组错误:

[com.sun.istack.internal.SAXException2: unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation]

这似乎来自这一行:

  

线程“主”中的异常javax.xml.bind.MarshalException    -具有链接的例外:   [com.sun.istack.internal.SAXException2:由于缺少@XmlRootElement批注,因此无法将类型“ java.lang.String”作为元素封送]       在com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:311)       在com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:236)       在javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)       在DVSClient.main(DVSClient.java:59)   由以下原因引起:com.sun.istack.internal.SAXException2:由于缺少@XmlRootElement批注,因此无法将类型“ java.lang.String”作为元素编组       在com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:234)       在com.sun.xml.internal.bind.v2.runtime.LeafBeanInfoImpl.serializeRoot(LeafBeanInfoImpl.java:127)       在com.sun.xml.internal.bind.v2.runtime.property.SingleReferenceNodeProperty.serializeBody(SingleReferenceNodeProperty.java:100)       在com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:345)       在com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:336)       在com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:336)       在com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:578)       在com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:326)       在com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:479)       在com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:308)   引用

我的主要代码如下:

public class Client {

public static void main(String[] args) throws MalformedURLException, ClassNotFoundException, IllegalAccessException, InstantiationException {


    URL UrlString = new URL("https://example.com.au:19443/Bus/exampleservice.svc?wsdl");
    String url02 = "https://example.com.au:19443/Bus/exampleservice.svc?wsdl";

    //Qname contains target namespace and name (port)
    QName qname = new QName("http://example/Contract/Service/Manager", "VerificationServiceBus", "Https");
    QName port = new QName("http://example/Contract/Service/Manager","DefaultSOAP11Binding_IVerification","Https");
    QName portName = new QName("Https");
    String serviceName = "VerificationServiceBus";
    CertificateRequest certificate = (new TestData()).test();
    URL newEndpoint = new URL("https://example.com.au:19443:19443/Bus/VerificationServiceBus.svc?");
    Service service = Service.create(UrlString, qname);

    try {

        IVerification myProxy = service.getPort(port,IVerification.class);

        VerificationResponse response = myProxy.verifyDocument(birthCertificate);
        System.out.println(response.getVerificationResultCode());

    }
    catch (IVerificationVerifyDocumentUnauthorizedAccessExceptionFaultFaultMessage ex) {
        System.out.println(ex.getMessage());

    }
}

}

我尝试手动进入某些类,并将@XMLRootElement添加到具有名称属性的类中,但仍存在相同的排序错误。

据我了解,编组和解组与将对象的内存表示形式转换为更适合转换的格式有关。虽然既然我所有的班级都生成了,不应该为我处理吗?

任何帮助将不胜感激。

谢谢

0 个答案:

没有答案