• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JAXB - complex hashmap

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 28430
103
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 28430
103
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see. So you really don't want

but instead you want
 
igor kvak
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 28430
103
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...)
 
reply
    Bookmark Topic Watch Topic
  • New Topic