I am using JAXB to generate java classes based on some XSD schemas. For an element such as:
<xsd:element name="REC_LOC" type="xsd:string" minOccurs="1"/>
jaxb generates the following code:
@XmlElement(name = "REC_LOC", required = true)
protected String recloc;
public String getRECLOC() {
return recloc;
}
/**
* Sets the value of the recloc property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setRECLOC(String value) {
this.recloc = value;
}
The problem is that we need to use some proprietary XML tools that rely on the naming convention of the getter/setter methods. For example, for the field REC_LOC they expect methods called getRecLoc(String value) and setRecLoc(), instead of getRECLOC().
Is there any way to customise the method names generated by jaxb?
You can use the jaxb:property
customization to customize the property name.
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<bindings schemaLocation="schema.xsd" version="1.0" node="/xs:schema">
<bindings node="xs:complexType[@name='SOME_TYPE']">
<bindings node="xs:sequence/xs:element[@name='REC_LOC']">
<property name="RecLoc"/>
</bindings>
</bindings>
</bindings>
</bindings>
(Not tested.)
See also:
globalBindings/@enableJavaNamingConventions
nameXmlTransform
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With