I am trying to marshall a message using the following snippet:
JAXBContext jContext = JAXBContext.newInstance(Iq.class); Marshaller m = newJAXBContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); Bind bind = new Bind(); bind.setResource("resource"); Iq iq = new Iq(); iq.setId(iqId); iq.setType("set"); iq.getAnies().add(bind); ByteArrayOutputStream baos = new ByteArrayOutputStream(); m.marshal(iq, baos);
Here, Iq and Bind are the objects formed from the relevant xmpp schemas. My problem is, with jaxb 2.0 and later versions, all the namespaces are declared in the root element:
resource
But, what is needed here is that the namespaces should occupy the appropriate places:
resource
Is there a way to marshall the xmpp stanzas as you see them in the 2nd xml stanza through JAXB 2.0 or later versions?
Long story short, I have 2 problems here: 1. Declaring the namespaces at appropriate locations. 2. removing the namespace prefix which I understand can be removed using the NamespacePrefixMapper? Not sure though, an example would be great.