2015-02-10 209 views
1

我們正在爲預定義的模式創建jaxb類。該模式包含某些使用xs:choice來創建complexType的元素。在這種情況下,生成的綁定包含一個List,這使得它非常複雜,因爲我們必須識別實際實例並進行投射。我們嘗試使用綁定自定義屬性「choiceContentProperty =」false「」來改變這種行爲。但這似乎並不奏效。任何建議來覆蓋這種行爲?將XML映射到Java對象庫

回答

1

免責聲明:我是jaxb2-simplify-plugin的作者。


這是jaxb2-simplify-plugin的用例。

此:

<xs:complexType name="typeWithElementsProperty"> 
    <xs:choice maxOccurs="unbounded"> 
     <xs:element name="foo" type="xs:string"/> 
     <xs:element name="bar" type="xs:int"/> 
    </xs:choice> 
</xs:complexType> 

通常會產生這樣的:

@XmlElements({ 
    @XmlElement(name = "foo", type = String.class) 
    @XmlElement(name = "bar", type = Integer.class), 
}) 
protected List<Serializable> fooOrBar; 

但隨着jaxb2-simplify-plugin你會得到這樣的:

@XmlElement(name = "foo", type = String.class) 
protected List<String> foo; 
@XmlElement(name = "bar", type = Integer.class) 
protected List<Integer> bar;