JAXB – how do i disable the Java Naming Convention in xjc?
•
Java
For example, some in XSD_ Property must be some in a Java class_ Property instead of someproperty
I tried to use globalbindings enablejavanamingconventions = "false" but it didn't work
Solution
You will need to use underscorebinding = "ascharinword" instead of enablejavamingconventions = "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
JAXB binding file is used to customize the mode of Java Transformation:
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"> <jaxb:globalBindings underscoreBinding="asCharInWord"/> </jaxb:bindings>
Xjc telephone
xjc -d out -b binding.xml customer.xsd
customer
The generated attribute name now contains underscore characters:
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; } }
Do not use binding xml
If you make the following xjc call instead:
xjc -d out -customer.xsd
You will see that the generated properties do not contain underscores:
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",required = true) protected String sOmEPROPerty; public String getSOmEproperty() { return sOmEPROPerty; } public void setSOmEPROPerty(String value) { this.somEPROPerty = value; } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码