We have been using Jersey (the Java REST library) for the project over the past few months and love it. But this week ran into a problem with JAXB.
I have an element that has 2 children, each of them has children, where some of their children turn to each other.
Let me show the code.
Root root = new Root(); Parent parent1 = new Parent(); Parent parent2 = new Parent(); root.add(parent1); root.add(parent2); Child child1 = new Child(); Child child2 = new Child(); Child child3 = new Child(); parent1.add(child1); parent1.add(child2); parent2.add(child2); parent2.add(child3);
So, we have 1 root, 2 parents and 3 children.
If I send this up and down the JAXB path, I seem to get 4 children back.
Each parent has its own copy of child2.
Anyway, to get JAXB to serialize the relationship and show that both parent1 and parent2 point to the same object?
We only recently discovered this problem when more complex elements were passed.
If there is no way to get JAXB to do this (what I believe at the moment), does anyone have any suggestions on how I could do some kind of magic in Jersey to restore the relationship?
source share