Seems like there should be something that can use reflection to look at an object and write out an XML. And then rebuild the object using XML. And it might not hurt to have a bit of an xdoclet like thing thrown in to talk about mapping particulars. Anybody know of such a beast?
Jakarta Digester JAX-B (XML binding) java.beans.XMLEncoder JOX (almost forgot this one) There are quite a few of these things ... each of them has good and poor aspects. It's all a matter of balance. The three above are a few that I know of, but seeing as how just about everybody loves XML these days, serializing beans to XML is just about everywhere and the libraries for them too. [ March 17, 2004: Message edited by: Nathaniel Stoddard ]
Check out skaringa - The default serialization settings isn't that "readable" but you can configure it to output something pretty sparse. I use it all the time in my apps and it works like a charm. Handles pretty much any type of object, and can generate schemas based on a Class.
Joined: May 29, 2003
I don't like the java.beans.XMLEncoder either -- it's too messy. Plus, if you start with an XML file, there's a chance it may not be able to correctly serialize it both ways. JAX-B is just psychotic. You need to create an XML schema firstly. Then you generate a DOM-like package full of all your classes. But it too is pretty crazy, with names that just aren't too easy on your brain cells. Digester as far as I know only will serialize one way (XML->Beans), but it's pretty flexible and decent. There's a definite de-coupling between the serialization mechanism and your Beans --- something that is definitely missing with the previous two approaches. JaxMe, JOX, Castor I haven't used. I think Castor is actually build on another Jakarta (or Apache) project that actually does the Bean/XML serialization, but you'll have to verify that. Then of course, you could always just write your own serialization routines with the DOM, but that's just a last resort -- one of these solutions will most likely fit your needs well.