Reputation: 13
I'm generating a top down web service with JAX-WS. In the wsdl I'm importing a xsd containing all necessary elements. I need all the xml nodes to be displayed in uppercase in soap request and hence I kept the element names in the xsd to upper case. But while generating the classes from the wsdl, I am able to see the getter and setter method are named in upper case as well but not the variables. For ex., if I use 'SOURCE' as an element in xsd, i'm getting the corresponding getter method as 'getSOURCE' instead of the normal convention 'getSource'. I tried to play by generating the jaxb classes from schema with keeping the xsd alone but i was not able to get the expected naming convention.
Below is a part of schema used
<xs:complexType name="Data">
<xs:sequence>
<xs:element name="SEQ" type="xs:int"/>
<xs:element name="INDEX" type="xs:string"/>
<xs:element name="VALUE" type="xs:string"/>
</xs:sequence>
This produces the following code after jaxb binding -
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Data", propOrder = {
"seq",
"index",
"value"
})
public class Data {
@XmlElement(name = "SEQ")
protected int seq;
@XmlElement(name = "INDEX", required = true)
protected String index;
@XmlElement(name = "VALUE", required = true)
protected String value;
public int getSEQ() {
return seq;
}
public void setSEQ(int value) {
this.seq = value;
}
public String getINDEX() {
return index;
}
public void setINDEX(String value) {
this.index = value;
}
public String getVALUE() {
return value;
}
public void setVALUE(String value) {
this.value = value;
}
}
Here setter method is getting generated as setSEQ and I need that to be in camel case like 'setSeq'.
Upvotes: 1
Views: 4730
Reputation: 44385
This is expected behavior. The underlying xjc
invocation is observing Java Bean conventions: If the first two letters of a property name are uppercase, no capitalization or decapitalization is applied to the get and set methods.
You can specify your own overriding method bindings in an JAXB external bindings file, which is an XML file that by convention has an .xjb
extension. Its format is described in chapter 7 of the JAXB specification:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.0"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:bindings schemaLocation="data.xsd">
<jaxb:bindings node="//xs:complexType[@name='Data']">
<jaxb:bindings node=".//xs:element[@name='SEQ']">
<jaxb:property name="seq"/>
</jaxb:bindings>
<jaxb:bindings node=".//xs:element[@name='INDEX']">
<jaxb:property name="index"/>
</jaxb:bindings>
<jaxb:bindings node=".//xs:element[@name='VALUE']">
<jaxb:property name="value"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Note that "data.xsd"
should be replaced with the relative URI of your schema file.
You would place the above in a file named something like custom.xjb
, then pass it to your wsimport invocation:
wsimport -d build/generated-classes -p com.example.myapp.data -b custom.xjb http://www.example.com/data-service.wsdl
Upvotes: 5