2

我有这个 xsd 架构:

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
       xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">

<xs:annotation>
    <xs:appinfo>
        <jaxb:globalBindings choiceContentProperty="true"/>
    </xs:appinfo>
</xs:annotation>

<xs:element name="request1">
    <xs:complexType>
        <xs:choice>
            <xs:sequence>
                <xs:element name="request2">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="xs:string" name="field1"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="request3">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="xs:string" name="field2"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>

            <xs:element name="request4">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element type="xs:string" name="field3"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

        </xs:choice>
    </xs:complexType>
</xs:element>

并且 Cxf codegen 插件生成的类带有List<Object>. 但我需要在 request1 类中使用 getter 和 setter 获取 request2、request3、request4 字段。有可能的?

4

1 回答 1

3

实际上,设置choiceContentPropertytrue会导致元素被映射到一个属性(List<Object>)。将其设置为false更改行为,即元素将被包装到单独的属性中。这将在此处更详细地解释。

如果您无法更改 XSD,则应考虑使用外部绑定文件

<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings version="2.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <jxb:globalBindings choiceContentProperty="false" />
</jxb:bindings>

注意:此行为只能全局设置,因此更改它也可能影响其他元素。

于 2014-04-11T06:48:10.943 回答