您好我有一个架构定义如下:
<complexType name="x">
<sequence>
<element name="year" type="date"/>
<choice>
<element name="comuneNascita" type="string" nillable="true"/>
<element name="statoNascita" type="string" nillable="true"/>
</choice>
</sequence>
</complexType>
当我尝试编组用xjc生成的类(使用xjc:simple选项)时,我得到了这个结果:
[...]
<statoNascita xsi:nil="true"/>
<comuneNascita>xxx</comuneNascita>
[...]
这是完全错的!
删除nillable =“true”解决了这个问题但是我必须指定一个有效的元素(不是nilled)。 任何解决方法?
答案 0 :(得分:0)
您可以通过如下注释属性来避免您的问题:
@XmlElements({
@XmlElement(name="comuneNascita", type=String.class),
@XmlElement(name="statoNascita", type=String.class),
})
您可以使用JAXB绑定文件让XJC生成如上所述的属性:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<globalBindings choiceContentProperty="true"/>
</bindings>
了解更多信息