users@jaxb.java.net

Re: Custom mapping for Maps in JAXB

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Wed, 23 Jun 2010 08:26:05 +0200

On 22 June 2010 19:31, Leo Romanoff <romixlev_at_yahoo.com> wrote:

>
>
>
> We have now discussed different strategies to resolve references.
> But one part of the solution is also to parse some xsd:any sub-elements,
> that are known to JAXB. For that a new JAXBUnmarshaller should be created
> from a JAXBContext (or current one could be reused???).


Don't use the same Unmarshaller twice at the same time.



> But AFAIK, inside
> XmlAdapter's marshal and unmarshal methods there is no way to access the
> current JAXBContext or current JAXBMarhsaller/JAXBUnmarshaller. Now, how
> can
> I create/get a proper JAXBContext if I don't know the current one?


In any given application, packages and/or classes define the set of
available JAXBContexts.

At the point where you create your (Un)Marshaller you ought to
know the Java Class name. Map them or their package names to the set
of JAXBContexts you need and access this global Map. Create the new
(Un)Marshaller from it.

I don't think it's worth to have this "root" context object passed down
the call tree, just in case some callback might need this. It may not be
convenient (ot even possible - think of duplicate XML tags bound to
different types in different places) to use the "root" context down there,
so a more general mechanism would be necessary.

-W