| Author |
JAXB - complex hashmap
|
igor kvak
Greenhorn
Joined: May 28, 2008
Posts: 15
|
|
Hi,
Hi,
I am quite new to JAXB and I have a following problem:
I want to marshall this class:
I am getting cyclic reference exception
could you please help me or give me any hint?
thanks a lot
|
Never trouble trouble till trouble troubles you
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 13842
|
|
|
I can't even imagine why you would want to have such a class, let alone marshal it to XML. However... can you give an example of what the marshalled XML would look like for a typical element of that class?
|
 |
igor kvak
Greenhorn
Joined: May 28, 2008
Posts: 15
|
|
Paul Clapham wrote:I can't even imagine why you would want to have such a class, let alone marshal it to XML.
implementing routing table - key is destination router, value is next-hop router; and the class is router itself - I know that it is quite an unusual data structure...
Paul Clapham wrote:However... can you give an example of what the marshalled XML would look like for a typical element of that class?
this would represent class A, where id=1 and map contains two entries:
key - object A with id 1; value = object A with id 2
key - object A with id 2; value = object A with id 3
so when marshalling HashMap, IDs will be used instead of real objects and when unmarshalling, IDs will be replaced with related objects
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 13842
|
|
I see. So you really don't want
but instead you want
|
 |
igor kvak
Greenhorn
Joined: May 28, 2008
Posts: 15
|
|
no
I really need
HashMap<A,A> because key and value are the same type as the class itself - once again: "key is destination router, value is next-hop router; and the class is router itself"
the problem is not how to marshall HashMap, but how to marshall hashmap that has cyclic referencies, e.g.:
A a1 = new A();
A a2 = new A();
map.put(a1,a1);
map.put(a2,a1);
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 13842
|
|
igor kvak wrote:no
I really need
HashMap<A,A> because key and value are the same type as the class itself - once again: "key is destination router, value is next-hop router; and the class is router itself"
But that wasn't what your XML example showed. So try again to show an example where your <Router> element has descendant elements which are also <Router> elements.
|
 |
igor kvak
Greenhorn
Joined: May 28, 2008
Posts: 15
|
|
|
well, if I use <Router> elements as children of root <Router> that would be cyclic reference, but I want to avoid that so instead of child <Router> elements, only IDs of these elements will be used - just like my example XML (maybe I should mentioned, that those numbers in <key> and <value> elements are router IDs, my bad...)
|
 |
 |
|
|
subject: JAXB - complex hashmap
|
|
|