2013-07-16 35 views
2

我有這樣的XSD架構:JAXB 2.0 XSD choiceContentProperty錯誤的行爲

<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代碼生成插件與List<Object>生成的類。但是我需要在request1類中使用getter和setter來獲取request2,request3,request4字段。有可能的?

回答

1

實際上,將choiceContentProperty設置爲true會導致元素映射到一個屬性(List<Object>)。將其設置爲false可以改變行爲,即元素將被包裝到單個屬性中。 這更詳細地解釋爲here

如果你不能改變你的XSD,你應該考慮使用external bindings files

<?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> 

注意:此行爲只能在全局設置,因此更改它也可能會影響其他元素。