I love XML. I love it so much that I dream about it. I sprinkle DTD declarations over my chicken and green beans for flavor. I’ve had urges to serialize my two year old daughter’s night-time feed-me rants into angle brackets and text. I scour the net in search of the perfect product that can unit test my XSLT templates, remove baldness and plan my retirement. The other day one of the developers at my job (a good buddy of mine) assaulted me with this simple idea. The assault was unprovoked. I was like sitting by myself in my fabric walled cubic corner when he materialized out of thin air and spoke to me. The words he spoke I will never forget. He said, aww shucks… what was it now? Oh yeah! He said, “Something something babble babble XStream…” That last word in his sentence stuck with me. (Primarily because it was the last and only word I actually heard.) It stuck because I had seen its site before.
I had visited the project page in the past. I had a desparate need for the product but I passed on it. Instead I wrote my own poor-man’s XStream API back then many months ago. (For those of you that only use your computer for checking email or paying phone bills “many months” in computer time is equivalent to several decades in human years.) The thought was, “These guys don’t know XML like I do! They don’t know what I need!” Well, in all honesty I had already promised a piece of software to my boss that was XStreams functional equivalent. While he would have readily accepted XStream in place of my humble code I made believe it was already done as I was being pushed for other deadlines. Writing my CliffStream API was actually pretty quick and lots of fun with a Test (*ahem* Behavioural) Driven Approach. I got it done in a day or two and it uses reflection with a little String API thingy that renames Collection and Array properties from their plural form into a singular tense. Eg. List getDogs() creates a “dogs” tag with nested “dog” tags. (Heh, You see that? I said “dog tags”!) Anyway, CliffStream sucks. It sucks because I wrote it. It sucks because it only works one way, objects-to-XML.
XStream stuck with me. My buddy-coworker came to me with the idea and it hit me over the head with a heavy mallet because it was just the thing I needed. I was assaulted. I wanted to fight back. I had no ammunition. I had no cause. He was innocent. Yet I felt assaulted. How dare this guy come and show me what an idiot I am for passing on the perfect fit solution to my then and now problems? Most of the damage from his assault originated from the realization of my unnecessary yanking an older brilliant idea of mine out of the core of our project to be used as an extension to my latest work. The brilliant idea is one of those fluent interfaces that I wrote about before. I currently need to serialize a GUI panel as XML and CliffStream is just too generic. It needs to be a specific schema. So I yanked on the older piece of code because using it makes it so much fun to write XML. As I yanked, 106 source files wiggled inplace. My IDE tried to help but I fought with it. It was a lot of work. It was work that I didn’t have to do now because of the assault. (The messenger is a good guy so I can’t fight back.)
XStream is “John-Blaze“
With a handful of SLOCs (Single Lines Of Code) you can read/write objects from/to XML. It’s really just that simple. There are dozens of uses for such a toy in the Java development you’re working on right now. You just need to dream them up. I really wanted to write a honest review of XStream rather than my life story and why I’m so stoopid for re-inventing the light-brite but I’m running short on time so you’ll just have to take my word for it and read the two-minute usage scenario. XStream is off the chains! If ya’ aint using it ya’ need ta start using it! If ya don’t know, now you know…