Thursday, November 27, 2008

JAXB vs Interfaces

A more detailed post about my battle with Spring (I WON) will follow soon.
Right now I want to talk about some JAXB stuff.
JAXB is our tool of choice to store scene descriptions to a xml file. We are not working with a predefined schema but with annotated classes.
After all the trouble that people gave us by including a (IMHO) outdated version of JAXB  in earlier JDK 6 versions (Note: There is STILL no nice way to replace libraries shipped with Java with different versoins. Is it really that hard to provide Java with some hooks that would allow developers to do that??)  we were very happy when JAXB 2 finally found its way into later releases.
But that's where the happiness ends. Don't get me wrong JAXB is a nice tool to handle  lot of different scenarios. But why the hell did they have to make it so complicated to use interfaces?
If you start googling for 'JAXB and Interfaces' you will find a ton of people having problems to get this to work.
One of the first links you will stumble over is probably this one. A nice round up of the whole issue.
But still.
Right now I need to annotate a class in Designer using @XmlElement(Object.class).
The reason is that I need to keep a reference to a class that implements a given interface. I can't assume that the interface is implemented by a certain class.
I can think of several reasons why this is a problem for an xml-file but there has to be a nicer way to do this.


No comments: