Jibx在多个结构中使用一个映射类变量

问题描述

我有以下映射:

<mapping class="MainClass" abstract="true">
    <structure name="SubAList" test-method="hasA" usage="optional" unmarshaller="com.test.MarshallA"
               marshaller="com.test.MarshallA">
    </structure>
    <structure name="SubBList" test-method="hasB" usage="optional">
        <collection add-method="addSubB" iter-method="createIterator" item-type="SubB" usage="optional">
            <structure name="SubB" usage="optional">
                <value style="attribute" name="identifier" get-method="getIdentifier" set-method="setIdentifier" usage="optional"/>
            </structure>
        </collection>
    </structure>
</mapping>

对应的类如下所示:

class MainClass {
    Collection<SubA> colA;
    Collection<SubB> colB;
    String valueForBoth = "abc";

    //.....
}

class SubA{
    // ......
}

class SubB{
    String identifier;
    //.....
}

是否可以在结构valueForBothMainClass中绑定类SubAList中的字符串SubBList?尽管在绑定中未将其声明为选择,但在生成的XML中,它始终始终仅为SubAListSubBList。这样就不会有多余的信息。

我知道使用SubA这样的自定义Marshaller类应该可行,但是使用纯XML绑定可行吗?

XML应该看起来像这样:

<MainClass>
   <SubA valueForBoth="abc"/>
</MainClass>

<MainClass>
   <SubB valueForBoth="abc"/>
</MainClass>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)