To the XStream

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.)

Johnny Blaze
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…

5 thoughts on “To the XStream

  1. That is so awesome. As one of the lovers of XML, I can completely relate to the way you feel. I started tracking it in mid 98 and I think it will be one of the most influential technologies for the coming decades.

  2. Yeah, XStream is a natural fit. Too bad it doesn’t look like it easily supports generating mixed content XML from custom converters. You say the project dates back to 98′? Wow! I think that’s about the time I got my first professional programming job! Let’s see, what was I doing then? RPG/400 work… nah I don’t think XStream would’ve helped me then but in the later years I sure wish I knew about it.

  3. Right, XML! That makes alot more sense, dating back to 98. Boy do I feel stoopid! I was trying to imagine what XML parsers would be available for JDK 1.0.7 and where object serialization might have been at the time!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s