PaulC
PaulC

Reputation: 41

Why does wsimport add @XmlSchemaType(name = "string")?

This is happening when I use a more recent version of wsimport. The example WSDL below contains a SimpleType "SomeEnum" that becomes an enum in the JAXB class. I have some code that generates the XSD schema back from the JAXB class and previously it would correctly assign the type tns:SomeEnum to this element but now treats it as string.

I eventually discovered that wsimport was adding the annotation @XmlSchemaType(name = "string"), causing this behavior. This seems wrong to me, because there is a more specific type than string. It is also breaking code that depends on back-generating the schema.

Here is the smallest WSDL I could come up with to reproduce the error.

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
  targetNamespace="http://foo.bar.com/example"
  xmlns:tns="http://foo.bar.com/example"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <wsdl:types>
    <schema elementFormDefault="qualified" jaxb:version="1.0"
      targetNamespace="http://foo.bar.com/example"
      xmlns="http://www.w3.org/2001/XMLSchema"
      xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:tns="http://foo.bar.com/example">
      <annotation>
        <appinfo>
          <jaxb:globalBindings typesafeEnumMaxMembers="999999"/>
        </appinfo>
      </annotation>
      <complexType name="Wrapper">
        <sequence>
          <element maxOccurs="1" minOccurs="0" name="someEnum" type="tns:SomeEnum"/>
        </sequence>
      </complexType>
      <simpleType name="SomeEnum">
        <restriction base="xsd:string">
          <enumeration value="SOME_VALUE"/>
          <enumeration value="ANOTHER_VALUE"/>
        </restriction>
      </simpleType>
      <element name="doesNothing">
        <complexType>
          <sequence>
          </sequence>
        </complexType>
      </element>
    </schema>
  </wsdl:types>

  <wsdl:message name="doesNothingRequest">
    <wsdl:part element="tns:doesNothing" name="parameters"/>
  </wsdl:message>

  <wsdl:portType name="SimpleTypeIssueServiceInterface">
    <wsdl:operation name="doesNothing">
      <wsdl:input message="tns:doesNothingRequest" name="doesNothingRequest"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="SimpleTypeIssueServiceSoapBinding" type="tns:SimpleTypeIssueServiceInterface">
    <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="doesNothing">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="doesNothingRequest">
        <wsdlsoap:body use="literal"/>
      </wsdl:input>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="SimpleTypeIssueService">
    <wsdl:port binding="tns:SimpleTypeIssueServiceSoapBinding" name="SimpleTypeIssueServiceInterfacePort">
      <wsdlsoap:address location="LOCATION_TEMPLATE"/>
    </wsdl:port>
  </wsdl:service>

And here is a fragment of the generated Wrapper.java. The @XmlSchemaType annotation is missing in Java7 wsimport (which I want) and present in Java8 wsimport. I don't know if this is fixing a bug or introducing one.

...
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Wrapper", propOrder = {
    "someEnum"
})
public class Wrapper {

    @XmlSchemaType(name = "string") // [Why is this added?]
    protected SomeEnum someEnum;

    /**
     * Gets the value of the someEnum property.
     *
     * @return
     *     possible object is
     *     {@link SomeEnum }
     *
     */
    public SomeEnum getSomeEnum() {
        return someEnum;
    }
...
}

Upvotes: 4

Views: 2521

Answers (1)

user1926275
user1926275

Reputation: 75

@XmlSchemaType(name = "string") protected SomeEnum someEnum; this means xsd type of this java property is xsd:string (base="xsd:string"). Look at A JAXB Nuance: String Versus Enum from Enumerated Restricted XSD String this for detailed explanation.

Upvotes: 1

Related Questions