WSDL generated Jaxb Add namespace prefix to only root element

1k views Asked by At

I am creating a soap web service using jaxb2 plugin. Hence I have generated jaxb classes from wsdl file. I have entered the sample of generated codes here.


    //ObjectFactory.java
        @XmlElementDecl(namespace = "http://xxxxx/", name = "InquiryResponse")
        public JAXBElement<InquiryResponse> createInquiryResponse(InquiryResponse value) {
            return new JAXBElement<InquiryResponse>(_InquiryResponse_QNAME, InquiryResponse.class, null, value);
        }
    
    //package-info.java
    @javax.xml.bind.annotation.XmlSchema(namespace = "http://XXXX/",
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED, 
    xmlns = {   
            @XmlNs(namespaceURI = "http://XXXX/", prefix = "ws")  
        })
    package X.X.X;
    
    import javax.xml.bind.annotation.XmlNs;

And the response is


    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
       <SOAP-ENV:Header/>
       <SOAP-ENV:Body>
          <InquiryResponse xmlns:ws="http://XXXX/">
             <InquiryResponse>
                <refId>0004440</refId>
                <status>UP</status>
             </InquiryResponse>
          </InquiryResponse>
       </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

But what I wanted is

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ws:InquiryResponse xmlns:ws="http://XXXX/">
         <InquiryResponse>
            <refId>0004440</refId>
            <status>UP</status>
         </InquiryResponse>
      </InquiryResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I am using a spring boot. Please help me. Thanks.
1

There are 1 answers

0
CatalinM On

I believe that happens because you specified elementFormDefault as UNQUALIFIED in your package-info.java. Try switching this to QUALIFIED to see if it helps.