JAXB生成后的错误注释类型



jaxb Generation i有一个包括我的int数组的错误类型的类,它用整数类型注释,而不是int []。

这是我的XSD:

<complexType name="GenericChartTask">
    <sequence>
        <element name="clients" type="struct:IDNameSiteServiceImageIndex"
            maxOccurs="unbounded" minOccurs="0">
        </element>
        <element name="commonTasks" type="struct:NameAndID"
            maxOccurs="unbounded" minOccurs="0">
        </element>
        <element name="groups" type="int" maxOccurs="unbounded"
            minOccurs="0"></element>
        <element name="siteServices" type="struct:SiteService"
            maxOccurs="unbounded" minOccurs="0">
        </element>
    </sequence>
</complexType>

这是我一代之后得到的:

public class GenericChartTask {
    @XmlElement(namespace = "http://american-data.com/ecs/struct")
    protected ad.ecs.struct.IDNameSiteServiceImageIndex[] clients;
    @XmlElement(namespace = "http://american-data.com/ecs/struct")
    protected ad.ecs.struct.NameAndID[] commonTasks;
    @XmlElement(namespace = "http://american-data.com/ecs/struct", type = Integer.class)
    protected int[] groups;
    @XmlElement(namespace = "http://american-data.com/ecs/struct")
    protected ad.ecs.struct.SiteService[] siteServices;
    ...

我也具有生成数组而不是列表的绑定,因为jaxb不想生成法律bean(它丢弃了列表的设置器)。

<jxb:bindings node="//xs:element[@name='groups']">
    <jxb:property collectionType="indexed" />
</jxb:bindings>

我的问题是,有什么方法可以摆脱故障的部分 type = integer.class ?因为当我想为此对象估算我的JSON时,它会引起问题。

它以Integer的形式生成,因为您在其上设置了minOccurs=0

整数在int不在的情况下是无效的。

删除此属性,它应以int。

的形式生成
<xs:element name="groups" type="xs:int">
</xs:element>

最新更新