Jeremy Haile wrote:
> When you unmarshal the following XML file, Castor would sometimes try to
> set the Apple field with the Orange or visa-versa, since it only looks
> at the XML ID:
>
> <myFruits>
> <basketOfFruit apple="myFruit" orange="myFruit" />
> <apple name="myFruit"/>
> <orange name="myFruit"/>
> </myFruits>
> So - now to my questions:
> 1) Has anyone else experienced these types of problems? Any ideas or
> solutions?
I think this is a general problem. It would be probably nice if the JAXB
RI / spec can generalize the ID processing. Applications can then use
this hook to plug their own reference integrity semantics.
The work around would be for you to resolve your pseudo-IDs into objects
within your object model (by hiding them behind the getApple() method),
or post-process the tree and fix up those references.
> 2) Is JAXB 2.0 smarter than Castor in this regard?
No. This is a validity violation, and unfortunately JAXB does not handle
this in a way you'd hope it to do. I hope you'd understand that it is
the correct handling of ID/IDREF semantics.
> 3) Does JAXB 2.0 provide a mechanism by which to deal with these types
> of problems.
Not right now, but this sounds like an interesting area to explore.
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com