AnsweredAssumed Answered

Problems with new IQ-API in 4.1.0-alpha7-SNAPSHOT

Question asked by Jens Offenbach on Dec 16, 2014
Latest reply on Dec 19, 2014 by Jens Offenbach

I have found a solution to make Smack full OSGi-compliant with minimum interference. I am currently migrating my code to 4.1.0-alpha7-SNAPSHOT, but I am confronted with a serious problem concerning the new IQ-API. I am using JAXB and put an extension to my IQs. At the moment I cannot find a possibility to create an IQ without defining the child element. It is part of the extension itself provided by JAXB. If I pass the child element name of the extension via the constructor the extension gets enclosed twice which breaks everything. Is there a way to return the whole extension as a valid XML string? This is my old code from 4.0.5 which did the job:


import org.jivesoftware.smack.packet.IQ;

import org.jivesoftware.smack.packet.Packet;

import org.jivesoftware.smack.packet.PacketExtension;

import org.jxmpp.jid.Jid;


public class JaxbMessageIQ extends IQ {


    private final PacketExtension payload;


    private JaxbMessageIQ(Builder builder) {

        payload = builder.payload;





    public CharSequence getChildElementXML() {

        return payload.toXML();



    public static Builder create() {

        return new Builder();



    public static Builder error() {

        return new Builder(IQ.Type.ERROR);



    public static Builder get() {

        return new Builder(IQ.Type.GET);



    public static Builder result() {

        return new Builder(IQ.Type.RESULT);



    public static Builder set() {

        return new Builder(IQ.Type.SET);



    public static class Builder {


        private PacketExtension payload;

        private IQ.Type type;

        private String to;

        private String from;

        private String packetId;


        private Builder() {




        private void init() {

            type = IQ.Type.GET;



        private Builder(IQ.Type type) {

            this.type = type;



        public Builder payload(PacketExtension payload) {

            this.payload = payload;

            return this;



        public Builder type(IQ.Type type) {

            this.type = type;

            return this;



        public Builder to(Jid to) {

            return to(to.asUnescapedString());



        public Builder to(String to) {

   = to;

            return this;



        public Builder from(String from) {

            this.from = from;

            return this;



        public Builder packetId(String packetId) {

            this.packetId = packetId;

            return this;



        public Builder response(Packet request) {




            return this;



        public JaxbMessageIQ build() {

            JaxbMessageIQ iq = new JaxbMessageIQ(this);

            if (type != null)


            if (to != null)


            if (from != null)


            if (packetId != null)



            return iq;