自定义xjb非常适合根据需要覆盖名称,但是我们会丢失名称中的下划线.
<?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>
Run Code Online (Sandbox Code Playgroud)
正如您在上面看到的xjb所见,生成的java代码是
@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;
}
Run Code Online (Sandbox Code Playgroud)
现在,一旦我将上面的xjb中的一行更改为:
<jxb:property name="_value" />
Run Code Online (Sandbox Code Playgroud)
java代码中的所有更改都是:
public List<Object> get_Value() {
if (value == null) {
value = new ArrayList<Object>();
}
return this.value;
}
Run Code Online (Sandbox Code Playgroud)
观察:"价值"
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"value"
})
Run Code Online (Sandbox Code Playgroud)
期望:"_ value"
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"_value"
})
Run Code Online (Sandbox Code Playgroud)
以下内容propOrder很好,因为@XmlAccessorType(XmlAccessType.FIELD)指定了 ,并且字段的名称是,value即使该属性称为 _Value (请参阅: http: //blog.bdoughan.com/2012/02/jaxbs-xmltype-and-proporder.html)。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"value"
})
Run Code Online (Sandbox Code Playgroud)
目标是让“value”在我的 json 中显示为“_value”
你的特殊_Value财产似乎能够容纳任何东西。您希望如何将内容呈现为 JSON?
@XmlMixed
@XmlAnyElement(lax = true)
protected List<Object> value;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1859 次 |
| 最近记录: |