Kum*_*aja 4 jaxb2 jaxb2-maven-plugin
我正在尝试为下面的示例 xsd 生成 JAXB 生成的对象。
<xs:complexType name="AddressType">
<xs:sequence>
<xs:element name="USA" type="xs:string"/>
</xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
没有任何自定义绑定生成的类是
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,字段名称是“usa”,setter/getters 是 getUSA/setUSA。
是否有任何自定义设置/绑定可以将字段名称生成为“USA”而不是“usa”,这样字段和属性都是“USA”。
但这是自定义属性,而不是字段..任何帮助
顺便说一句,我正在使用 maven-jaxb2-plugin
您的情况中的示例 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>
Run Code Online (Sandbox Code Playgroud)
使用 xjc 命令添加 -b binding.xjb 或在 Maven xjc 插件中配置绑定文件位置。
| 归档时间: |
|
| 查看次数: |
3608 次 |
| 最近记录: |