Hi Rohit,
There is no general solution to this issue, but you should be able to
come up with a solution that works for your particular case. First off,
what's the relationship between these different classes and the linkages
- are the ClassB references to the ClassA which contains them it it's
list? If so, you should probably leave the ClassB links to ClassA out of
the XML representation completely, and let them be implied by
containment (so the XML for a ClassA instance will contain the XML
representations for a bunch of ClassB instances). In that case you can
use a pre-set method to set the linkage back to the parent ClassA at the
time you're unmarshalling a ClassB instance (see the Order/Item
relationship in the example
http://jibx.sourceforge.net/tutorial/binding-extend.html#extmeths).
If the relationship is more complex, you probably need to do some
preprocessing before the actual unmarshalling. For instance, say ClassA
has a list of ClassB instances, some of which have links to other ClassA
instances. If the ClassB instances can be shared between ClassA lists
you'll need a method that collects the closure of all the referenced
ClassA and ClassB instances (basically just recursively going through
all the instances of each, adding them to sets), and want to marshal out
the entire set of each type at one time. In that case you'd want to use
ID/IDREF links between the ClassA and ClassB XML representations.
Hope that gets you pointed in the right direction. If you supply more
details of the relationship between these classes I can give you more
precise advice.
- Dennis
Rohit Seth wrote:
Hi All,
I am quite new to JibX and need some help rergarding mapping of classes
with circular references.
In my case ClassA contains a set of objects of classB and ClassC while
ClassB and ClassC contains a member of type ClassA.
I used the following mapping for binding but when I start marshalling the
objects it goes into infinite loop due to circular refereces.
I'll appreciate if someone can help me out of the situation.
thanks
<mapping class="example.ClassA">
<value name="id" field="id" usage="optional"/>
<value style="element" name="name" field="name" usage="optional"/>
<value style="element" name="description" field="description"
usage="optional"/>
<collection name="setOfClassB" field="setOfClassB"
item-type="example.ClassB"/>
</mapping>
<mapping class="example.ClassB">
<value name="id" field="id" usage="optional"/>
<value style="element" name="desc" field="desc" usage="optional"/>
<structure name="varClassA" field="varClassA" usage="optional"/>
</mapping>
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users