Jibx: integrating base class inference into class extension
I have this cool model:
abstract class A {
int a;
}
class B extends A {
int b;
}
class C extends B {
int c;
}
And I would like to get the jibx to output this XML:
<B b=1 a=0>
<children>
<C c=2 b=1 a=0/>
</children>
</B>
I have an xml binding:
<binding>
<mapping class="A" abstract="true">
<value name="a" field="a" style="attribute" usage="optional"/>
<collection field="children" type="java.util.ArrayList"/>
</mapping>
<mapping name="B" class="B" extends="A">
<value name="b" field="b" style="attribute" usage="optional"/>
<structure map-as="A"/>
</mapping>
<mapping name="C" class="C" extends="B">
<value name="c" field="c" style="attribute" usage="optional"/>
<structure map-as="B"/>
</mapping>
</binding>
However, I keep getting artifacts like this:
<C c=2>
<B b=1 a=0>
<children>
...
</children>
</B>
</C>
As a workaround, I changed my inheritance structure to have AbstractB and B extend AbstractB and C extend AbstractB, but it really annoys me to rebuild my class due to JiBX.
Does anyone know how to solve this?
Edit: As a bonus question - how do you code / decode the java.util.Map with Jibx? I know this is impossible to do initially (would be glad to be refuted!), But what would you do to copy the map (no lines). Please note that we are not using jibx-extras.jar, so solutions should not rely on it.
a source to share
Actually IMHO it seems okay to get C as the parent (in the XML sense) of B, because C contains B's information (from which it inherits) and its own information aside , but B is unaware of such information related to C. right?
To make it clearer: he is B Bird and C is Chicken . The chicken is a bird, so C inherits form B, OK. But the XML format will store:
<Bird color="brown">
<Chicken label="Kentucky-fried" />
</Bird>
or
<Chicken label="Kentucky-fried"> <!-- chicken-specific information -->
<Bird color="brown" /> <!-- "birdy" part of the chicken -->
</Chicken>
?
So, from a model point of view it seems logical to me ... And I didn't find a way to achieve the opposite in the binding tutorial , sorry.
a source to share