问题描述
自定义xjb非常适合覆盖名称,但是我们会丢失名称中的下划线。
The custom xjb works great for overriding the names as desired however we lose the underscores in the names.
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:globalBindings underscoreBinding="asCharInWord"/>
<jxb:bindings schemaLocation="foo.xsd">
<jxb:bindings node="//xs:complexType[@name='fooType']">
<jxb:property name="value" />
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
正如您在上面看到的xjb所见,生成的java代码是
As you can see for the above xjb the java code generated is
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"value"
})
public class FooType {
@XmlMixed
@XmlAnyElement(lax = true)
protected List<Object> value;
......
public List<Object> getValue() {
if (value == null) {
value = new ArrayList<Object>();
}
return this.value;
}
现在,我将上面的xjb中的一行更改为:
Now, once I change one line in the xjb above to:
<jxb:property name="_value" />
java代码中的所有更改都是:
All that changes in the java code is :
public List<Object> get_Value() {
if (value == null) {
value = new ArrayList<Object>();
}
return this.value;
}
观察到:value
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"value"
})
所需:_ value
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"_value"
})
推荐答案
以下 propOrder
没问题,因为指定了 @XmlAccessorType(XmlAccessType.FIELD)
,并且该字段的名称是值
即使该属性名为_Value(请参阅:。
The following propOrder
is fine since @XmlAccessorType(XmlAccessType.FIELD)
is specified and the name of the field is value
even though the property is called _Value (see: http://blog.bdoughan.com/2012/02/jaxbs-xmltype-and-proporder.html).
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"value"
})
你的特定 _Value
属性似乎能够持有任何东西。你想如何将内容呈现为JSON?
Your particular _Value
property appears to be to be able to hold anything. How do you want the contents to be rendered to JSON?
@XmlMixed
@XmlAnyElement(lax = true)
protected List<Object> value;
这篇关于使用保留下划线的xjb覆盖JAXB属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!