我试图为下面的示例xsd生成JAXB生成的对象。
<xs:complexType name="AddressType">
<xs:sequence>
<xs:element name="USA" type="xs:string"/>
</xs:sequence>
</xs:complexType>
并且没有任何自定义绑定生成的类是
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AddressType", propOrder = {
"usa"
})
public class AddressType {
@XmlElement(name = "USA", required = true)
protected String usa;
/**
* Gets the value of the usa property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getUSA() {
return usa;
}
/**
* Sets the value of the usa property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setUSA(String value) {
this.usa = value;
}
}
如您所见,字段名称为&#34; usa&#34;和setter / getters是getUSA / setUSA。
是否有任何自定义设置/绑定使字段名称也生成为&#34; USA&#34;而不是&#34; usa&#34;,这样的领域和财产都是&#34; USA&#34;。
我提到How to customize property name in JAXB?
但这是自定义属性,而不是字段..任何帮助
顺便说一句,我使用的是maven-jaxb2-plugin
答案 0 :(得分:3)
示例中的xjb文件:binding.xjb
示例:
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<jaxb:bindings schemaLocation="schema.xsd">
<jaxb:bindings node="//xs:element[@name='USA']">
<jaxb:property name="usa" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
使用xjc命令添加-b binding.xjb或在maven xjc插件中配置绑定文件位置。