2015-02-10 207 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;