powered by Jive Software

Using JAXB with SMACK as IQ parser

Hi all,

I’m currently using Smack in combination with JAXB. I use the latter for (un)marshalling my custom IQ messages. The reason for this is that for me it increases development time significantly. Creating the wrapper for the XmlPullParser (so that it looks like a javax.xml.stream.XMLStreamReader) was doable and building a IQProvider which can (un)marshall any java object (annotated with @XmlRootElement and some other things related to namespaces) was ok as well. I did have the problem that when I tried to marshall any object which inherits from IQ, JAXB will fail (because it some fields which it can’t marshall). Which is OK, as these fields mustn’t be marshalled in the first place. However since I don’t have access to the IQ class to mark these fields as @XmlTransient, that was a (sort of) dead end. Right now I’m resorting to using a wrapper class which delegates to the generic jaxb / smack bridging code.

All and fine, I’m happy with this all, but I was wondering whether other people couldn’t benefit from this. For any smack developers out there: would there be interest in this? I noticed that the most recent release isn’t that recently actually … is there any development going on?

Cheers,

Frens

Hi Frens,

I was just searching the forums for JAXB for the same reason – we’re using a number of custom IQ messages and using JAXB to marshal/ unmarshal would be tremendously helpful in terms of reducing parsing and serialization logic errors.

If you’re willing to share your code I’d definitely be interested.

Also wondering if the Ignite team has any plans to move from the XmlPull.org to StAX which would make this sort of wrapper unnecessary, as well as moving to a more widely used API.

As an alternative, it just occurred to me that XStream can work directly with XPP so there’s an alternative to wrapping everything for JAXB.

Here I come back two years later to answer my own question… The solution is to use PullUnmarshaller, a class which was written as part of Sun’s JAXB v1 samples. I’ve written about it here, in case anyone new to Smack stumbles across this problem:

http://blog.thomnichols.org/2012/06/using-smack-xmpp-with-jaxb

1 Like