users@jaxb.java.net

Re: JAXB newbie questions

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, 27 Nov 2007 09:01:13 +0100

Hi.

> > Although I like beans better.
>
> I agree. You can take design-to-interface too far, in my opinion, and
> while interfaces are a good fit for service classes, I'd say they're
> overkill for javabeans.
>
> Note that JAXB1 did generate interfaces and impl classes, and frankly,
> it was too heavyweight.

I think the main point of generaing interfaces and classes in JAXB1
was that implementation classes were WAY too heavy with all those
marshallers/unmarshallers and so on.

> > These are data objects. Should not be too smart.
> > You can use plugins to add features. Many of the plugins are available
> > here: https://jaxb2-commons.dev.java.net
> > For the task you describe, take
> > https://jaxb2-commons.dev.java.net/value-constructor/
>
> The value-constructor plugin does the job (mostly), but it doesn't scale
> well at all, in that when your type has many fields (inherited or
> declared), the constructor very quickly becomes unwieldy.
>
> I much prefer to use Hanson's fluent-api plugin instead, it results in
> much, much readable code than value-constructor.

It's even better when that you have the choice. :)

> And also, JAXB does generate an ObjectFactory (or is that a
> customisation? I can't remember) than creates instances of your
> objects, but all it does is call the constructor and return it, so it's
> rather pointless (just there for JAXB1 compatability, I think).

No, not exactly.
There's a point of ObjectFactory in scenarios where you have
substitutionGroups for instance. Object factory also provides very
interesting possibilities for extensions/customizations (like this
one: https://jaxb.dev.java.net/guide/Adding_behaviors.html)

Bye.
/lexi