自定义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>
正如您在上面的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;
}
现在,我将上面的xjb中的一行更改为:
<jxb:property name="_value" />
java代码中的所有更改都是:
public List<Object> get_Value() {
if (value == null) {
value = new ArrayList<Object>();
}
return this.value;
}
观察:“值”
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"value"
})
所需:“_ value”
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"_value"
})
答案 0 :(得分:0)
以下propOrder
很好,因为指定了@XmlAccessorType(XmlAccessType.FIELD)
且字段名称为value
,即使该属性名为_Value(请参阅:http://blog.bdoughan.com/2012/02/jaxbs-xmltype-and-proporder.html)。 / p>
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "textType", propOrder = {
"value"
})
目标是让“值”在我的json中显示为“_value”
您特定的_Value
财产似乎可以保留任何内容。您希望如何将内容呈现为JSON?
@XmlMixed
@XmlAnyElement(lax = true)
protected List<Object> value;