Using Smack XMPP with JAXB
Nobody on the Smack forums had seemed to figure out a way to do it. The reason it's so difficult is, Smack uses the XmlPull v1 API, which is the predecessor to StAX. (StAX is what JAXB generally uses, but the APIs are not compatible.)
Well, after a bunch more searching, I finally stumbled into Sun's JAX-WS example code. Hidden in there is this gem: PullUnmarshaller.java. It adapts an XmlPull v1 parser to JAXB! Perfect, my work is done! Well, not quite. Initial behavior indicated that I was getting a single message into my plugin, and then nothing after that. What gives? After some debugging, it turns out that PullUnmarshaller is consuming the closing tag event, which Smack doesn't like.
So, you have to modify PullUnmarshaller and comment out this one line:
250.// skips the last end element.251.pp.next();Do that, and PullUnmarshaller works wonderfully! I hope to post a fully working example soon, I'll post a link here when I do.
0 Comments