The problem is that webservice contracts (at least compatible with the WS-I base profile) cannot encode links to other objects in the message. That is, a field of a reference type is always sorted by the marshalls of the fields of the object to which it refers. This recursion is infinite if the object graph contains a loop.
That is, if you had:
class A { String name; A a; }
and did:
A a = new A(); a.name = "hello"; aa = a; marshall(a);
XML will look like
<a> <name>hello</name> <a> <name>hello</name> <a> <name>hello</name> <a> ...
To avoid this, the cycle must be broken. Typical approaches are to make the association available in only one direction, set a null backlink before marshalling (instruct the recipient to restore them), move the associations to separate classes, for example,
class A { String name; } class B { String adress; } class AWithB { A a; B b; }
and many other options.
source share