For example sOmE_PROPerty in xsd must be sOmE_PROPerty in java class not someProperty.
I tried to use globalBindings enableJavaNamingConventions="false" but it doesn't work.
CamelCase in Java naming conventions Java follows camel-case syntax for naming the class, interface, method, and variable.
XJC is a Java SE tool that compiles an XML schema file into fully annotated Java classes. It is distributed within the JDK package and is located at /bin/xjc path.
7.1. The JAXB-2 Maven plugin uses the JDK-supplied tool XJC, a JAXB Binding compiler tool that generates Java classes from XSD (XML Schema Definition). By default, this plugin locates XSD files in src/main/xsd.
For variables, the Java naming convention is to always start with a lowercase letter and then capitalize the first letter of every subsequent word. Variables in Java are not allowed to contain white space, so variables made from compound words are to be written with a lower camel case syntax.
You will need to use underscoreBinding="asCharInWord"
instead of enableJavaNamingConventions="false"
:
customer.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
targetNamespace="http://www.example.org/customer"
xmlns="http://www.example.org/customer"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:complexType name="customer">
<xsd:sequence>
<xsd:element name="sOmE_PROPerty" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
binding.xml
A JAXB binding file is used to customize the schema to Java conversion:
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jaxb:globalBindings underscoreBinding="asCharInWord"/>
</jaxb:bindings>
XJC Call
xjc -d out -b binding.xml customer.xsd
Customer
The generated property names now include the underscore character:
package org.example.customer;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "customer", propOrder = {
"sOmEPROPerty"
})
public class Customer {
@XmlElement(name = "sOmE_PROPerty", required = true)
protected String sOmEPROPerty;
public String getSOmE_PROPerty() {
return sOmEPROPerty;
}
public void setSOmE_PROPerty(String value) {
this.sOmEPROPerty = value;
}
}
Without Using binding.xml
If you instead make the following XJC call:
xjc -d out -customer.xsd
You will see that the generated properties do not include the underscore:
package org.example.customer;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "customer", propOrder = {
"sOmEPROPerty"
})
public class Customer {
@XmlElement(name = "sOmE_PROPerty", required = true)
protected String sOmEPROPerty;
public String getSOmEPROPerty() {
return sOmEPROPerty;
}
public void setSOmEPROPerty(String value) {
this.sOmEPROPerty = value;
}
}
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