自定义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"
})发布于 2013-05-29 20:45:49
下面的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"
})目标是在我的json中以"_value“的形式显示"value”。
您的特定_Value属性似乎能够保存任何内容。您希望如何将内容呈现给JSON?
@XmlMixed
@XmlAnyElement(lax = true)
protected List<Object> value;https://stackoverflow.com/questions/16821060
复制相似问题