0

My XSD is

<element name="GetCertificateByServiceName" >
    <complexType>
        <sequence>
            <element ref="tns:ServiceName" />
        </sequence>
    </complexType>
</element>    
<element name="ServiceName" type="string" />

Inspite of having S as capital the sub element is generated as "serviceName"

POJO Class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "serviceName"
})
@XmlRootElement(name = "GetCertificateByServiceName")
public class GetCertificateByServiceName {

    @XmlElement(name = "ServiceName", required = true)
    protected String serviceName;

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String value) {
        this.serviceName = value;
    }

XML Generated

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header />
   <S:Body>
      <ns2:GetCertificateByServiceName xmlns:ns2="http://example.com/xsd/1.0">
         <serviceName>ManagerService</serviceName>
      </ns2:GetCertificateByServiceName>
   </S:Body>
</S:Envelope>

Expected It should be ServiceName instead of serviceName and ns2 should be associated with ServiceName:

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header />
   <S:Body>
      <ns2:GetCertificateByServiceName xmlns:ns2="http://example.com/xsd/1.0">
         <ns2:ServiceName>ManagerService</ns2:ServiceName>
      </ns2:GetCertificateByServiceName>
   </S:Body>
</S:Envelope>
parag gupta
  • 84
  • 1
  • 5
  • Move the annotation from the field to the getter method. – Andreas Jan 18 '21 at 08:44
  • Not Working either. Same result – parag gupta Jan 18 '21 at 08:52
  • The JAXB in my jdk1.8.0_181 on Windows generates the name in correct mixed case. Don't know what SOAP library you're using, but must be an issue with it. --- As for the missing namespace prefix, that is something you ask for in the `package-info.java` file, where the namespace is defined. See e.g. the `elementFormDefault = XmlNsForm.QUALIFIED` attribute in [JAXB :Need Namespace Prefix to all the elements](https://stackoverflow.com/a/7736235/5221149). – Andreas Jan 18 '21 at 09:15
  • I already tried those methods before raising this question. It's like JAXB Annotation not working – parag gupta Jan 18 '21 at 09:29
  • It works in JAXB, but apparently not in the SOAP library you're using, so file a bug, upgrade to a newer version, or use a different library. – Andreas Jan 18 '21 at 09:33
  • Just to be sure, you did import the correct `@XmlElement` right? I.e. `javax.xml.bind.annotation.XmlElement`, not e.g. `com.sun.xml.internal.txw2.annotation.XmlElement` – Andreas Jan 18 '21 at 09:35
  • In the POJO class, Yes! – parag gupta Jan 18 '21 at 09:40

0 Answers0