users@jaxb.java.net

Re: deriving from JAXB2 generated classes

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 06 Dec 2006 15:53:22 -0800

Sorry for the delay in the response. I was taking vacation after
Thanksgiving. It's good to hear from you, as always.

James Strachan wrote:
> I know we can provide base classes for JAXB2 POJOs, I'd actually like
> to go the other way, and occasionally derive from JAXB2 POJOs and use
> the derivations by default on all parsing/marshalling stuff.
>
> I know I can derive from ObjectFactory and write my own custom one. I
> was kinda wondering if there was some way to kinda get the JAXB2 XJC
> to generate - if I flipped some switch - an ObjectFactorySupport that
> I can then derive from to implement my own custom ObjectFactory
> implementation - so that it'd be kinda invisible that I'd used a
> custom ObjectFactory - so there'd be no need to do custom JAXBContext
> stuff etc? i.e. I could kinda wire in derived classes to the JAXB2
> generated code.
>
> I wonder has anyone done something like this?

I'd like to better understand what you are trying to do.

I see two pains in using a custom ObjectFactory class today. One is that
you have to set the instance of it to Unmarshaller, and the other is
that the generated method signatures don't show your custom classes.
Which one is hurting you more? It sounded like the latter (and fixing
latter should bring in the former automatically), but I wasn't sure.

And I'm not sure how XJC would recognize what classes you are using to
subclass what XJC generated? By having you mention their names in the
customization?


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com