[英]How to customize property name in JAXB?
我正在使用JAXB基于一些XSD架构生成java类。 对于如下元素:
<xsd:element name="REC_LOC" type="xsd:string" minOccurs="1"/>
jaxb生成以下代码:
@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;
}
问题是我们需要使用一些依赖于getter / setter方法命名约定的专有XML工具。 例如,对于字段REC_LOC,它们期望使用名为getRecLoc(String value)和setRecLoc()的方法,而不是getRECLOC()。
有没有办法自定义jaxb生成的方法名称?
您可以使用jaxb:property
customization来自定义属性名称。
<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>
(未经测试。)
也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.