users@jaxb.java.net

Re: JAXB Unmarshalling and XmlIDREF using different stores

From: Florian Thiel <flo.thiel+javanet_at_googlemail.com>
Date: Tue, 4 Dec 2007 13:19:30 -0500

On Nov 29, 2007 4:24 PM, Aleksei Valikov <valikov_at_gmx.net> wrote:
>
> Hi.
>
> > We're using JAXB 2.1 to marshal/unmarshal Java objects to an XML
> > database and to different files. Some objects contain XmlIDREFs to
> > objects stored in another file. On unmarshalling one of these objects
> > the referencing attribute is set to "null" because JAXB cannot resolve
> > the reference. Is there a way around this? We store IDs and fill the
> > referenced objects manually as an ugly workaround. Do all the elements
> > referencing each other have to be in the same document for JAXB to
> > work? There does not seem to be a callback mechanism to resolve the
> > references on misses.
> >
> > Does the non-goal "traversal of JavaBean object graphs" mean this will not work?
>
> You'll just need to provide a custom id resolver.
>
> http://weblogs.java.net/blog/kohsuke/archive/2005/08/pluggable_ididr.html

Thanks a lot! That was exactly what I was looking for. Now I wrote an
IDResolver for testing and my startDocument method doesn't get called
(checked with debugger and debug strings). How could that be? Isn't
startDocument guaranteed to be called when marshalling starts?

FYI: We're using JAXB2.1 and this is the resolver setup code:

---
JAXBContext ctx = JAXBContext.newInstance(RootLevel.class);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
unmarshaller.setProperty(IDResolver.class.getName(), new LevelTypeResolver());
Object object = unmarshaller.unmarshal(in);
---
Thanks in advance,
Florian