users@jaxb.java.net

Re: toString() methods on generated classes

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 13 Sep 2006 17:20:34 -0700

Hanson Char wrote:
> Thinking about the toString() method in jaxb generated classes, one
> obvious/easy approach is to generate one (eg via plugin) to make use of the
> jarkata commons' ToStringBuilder.reflectionToString(...) method.

Yes. That could work, and that can be implemented quickly (important!)
But since you are in position to be able to generate code, I think
generating the dumb toString() is not a bad idea either. It reduces a
dependency, for one thing.

> How about the thought of defining a toXml() to return the xml string of the
> current jaxb pojo instance ? AFAIK, such toXml() can be easily/nicely done
> using XStream ... But how about the idea of using jaxb marshaller instead ?
> Is speed or validation a concern ? (XStream does no validation.)

I'm with Kirill on this one, but hey, if XStream works for you, that's
one way to do it.

I think using JAXB would be also not that hard. The only thing you need
to be careful is that if the class doesn't have @XmlRootElement (you can
tell that from !CClassInfo.isElement()), then you need to wrap it to
JAXBElement before you marshal.

But I think it's pretty simple code to generate.


> I don't mind to integrate these extra methods into the fluent-api plugin, if
> this is considered sensible.

Go for it!

The only thing is that even if all these features are implemented in the
same jar file, you'd still want to have different pages on
http://jaxb2-commons.dev.java.net/, because the audience is different.

It's the same thing I wrote to Lexi, but if I were just looking for the
toString() plugin, it would never occur to me to look at the fluent-api
plugin. So it's important that it's listed separately on
https://jaxb2-commons.dev.java.net/

If it's not too much overhead to handle multiple small projects, I'd
actually suggest you create a different source tree and etc. But that's
up to you.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com